在Laravel 5.3的数据库中的图像上添加水印 [英] Adding watermark on image from databases in Laravel 5.3

查看:45
本文介绍了在Laravel 5.3的数据库中的图像上添加水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Intervention Image软件包在Laravel中的数据库上的图像上添加水印.在我的数据库表中,我正在保存图像的路径.我在模型中使用访问器来访问图像路径的字段,但出现此错误:

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:

方法插入不存在.

这是我的模特:

这是我的刀刃:

推荐答案

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

这篇关于在Laravel 5.3的数据库中的图像上添加水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆