您的位置 首页 php

如何使用Laravel图片处理包intervention-image

下面由Laravel教程栏目给大家介绍如何使用Laravel图片处理包intervention-image,希望对需要的朋友有所帮助!

最近偶然发现了Laravel可用的图片处理包intervention-image。
文档地址:http://image.intervention.io
安装起来也很简单。

composer require intervention/image

然后到config/app.php的
$providers中添加

Intervention\Image\ImageServiceProvider::class

$aliases中添加

'Image' => Intervention\Image\Facades\Image::class

使用时引入Image的命名空间 use Intervention\Image\Facades\Image;
这样就可以使用Image来方便的处理图片了。

基本操作:

$img = Image::make('public/foo.jpg')->resize(300, 200);$img->save('public/bar.png');

save()也可以不填写路径,不填默认为覆盖原图。

intervention通常会在PHP脚本完成后会自动销毁资源。
也可以使用destroy()方法主动销毁资源,在调用方法后,图像实例不再可用。

$img = Image::make('public/foo.jpg');$img->resize(320, 240);$img->save('public/small.jpg');$img->destroy();

此处有一坑,save()覆盖原图时,destroy()不能正常销毁。save()为不同文件,可正常使用destroy()。

文章来源:智云一二三科技

文章标题:如何使用Laravel图片处理包intervention-image

文章地址:https://www.zhihuclub.com/27195.shtml

关于作者: 智云科技

热门文章

网站地图