Adding watermark on image from databases in Laravel 5.3

China☆狼群 提交于 2019-12-24 05:07:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!