在字符串上调用成员函数insert()

时间:2018-04-28 10:42:56

标签: php laravel intervention gdlib

我想在laravel中使用intervention image库为我上传的图片添加水印。我已通过命令composer require intervention/image安装了它  ,在providers数组中添加Intervention\Image\ImageServiceProvider::class,在别名数组中添加'Image' => Intervention\Image\Facades\Image::class

这是我的代码示例:

if($request->file1)
    {
        $this->validate($request, [
            'file1' => 'required|image|mimes:jpeg,png,jpg,gif,svg',
        ]);
        $imageName = time().'-'.rand(11111, 99999).'.'.$request->file1->getClientOriginalExtension();
        $imageName = $imageName->insert('https://www.exabytes.my/wp-content/uploads/400x150-exabytes-logo.png','center');
        $request->file1->move('theme/img/properties', $imageName);
    }

1 个答案:

答案 0 :(得分:1)

您必须实际使用Image class / facade:

$imageName = time().'-'.rand(11111, 99999).'.'.$request->file1->getClientOriginalExtension();
$file = $request->file1->move('theme/img/properties', $imageName);
$source = 'https://www.exabytes.my/wp-content/uploads/400x150-exabytes-logo.png';
Image::make($file->getPath())->insert($source, 'center');