阿里云新用户优惠

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()。

阅读更多...