问题
I am trying to add watermark on image from database in Laravel using Intervention Image package. In my database table I am saving the path of the image. I am using Accessors in my model to get access to the field of the image path but I am getting this error:
Method insert does not exist.
Here is my model:
Here is my blade:
回答1:
public function getFilePathAttribute($value){
$img = Image::make(public_path($value)); //your image I assume you have in public directory
$img->insert(public_path('watermark.png'), 'bottom-right', 10, 10); //insert watermark in (also from public_directory)
$img->save(public_path($value)); //save created image (will override old image)
return $value; //return value
}
It is better to do it on upload so you do it Once not always when trying to access the image path from DB (less proccess) FYI: this will save already watermarked image
来源:https://stackoverflow.com/questions/41182385/adding-watermark-on-image-from-databases-in-laravel-5-3