The following tutorial column of Laravel will introduce to you how to use the Laravel image processing package intervention-image. I hope it will be helpful to friends in need!
#I recently accidentally discovered the image processing package intervention-image available for Laravel.
Document address: http://image.intervention.io
It is also very simple to install.
composer require intervention/image
Then add
Intervention\Image\ImageServiceProvider::class
$providers in config/app.php and add
'Image' => Intervention\Image\Facades\Image::class
Introduce the namespace of Image when using it use Intervention\Image\Facades\Image;
This way you can use Image to process images conveniently.
Basic operation:
$img = Image::make('public/foo.jpg')->resize(300, 200); $img->save('public/bar.png');
save() can also not fill in the path. If not filled in, the original image will be overwritten by default.
intervention usually automatically destroys resources after the PHP script is completed.
You can also use the destroy() method to actively destroy resources. After calling the method, the image instance is no longer available.
$img = Image::make('public/foo.jpg'); $img->resize(320, 240); $img->save('public/small.jpg'); $img->destroy();
There is a pitfall here. When save() overwrites the original image, destroy() cannot destroy it normally. save() is a different file and destroy() can be used normally.
The above is the detailed content of How to use Laravel image processing package intervention-image. For more information, please follow other related articles on the PHP Chinese website!