Home>Article>PHP Framework> How to use Laravel image processing package intervention-image

How to use Laravel image processing package intervention-image

藏色散人
藏色散人 forward
2020-07-13 13:53:28 3913browse

The following tutorial column ofLaravelwill introduce to you how to use the Laravel image processing package intervention-image. I hope it will be helpful to friends in need!

How to use Laravel image processing package intervention-image

#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

$aliases to

$providers in config/app.php and add

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

Introduce the namespace of Image when using ituse 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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete