Home > PHP Framework > Laravel > body text

How to use Laravel image processing package intervention-image

藏色散人
Release: 2020-07-13 13:53:28
forward
3986 people have browsed it

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!

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
Copy after login

Then add

Intervention\Image\ImageServiceProvider::class
Copy after login

$aliases to

$providers in config/app.php and add

'Image' => Intervention\Image\Facades\Image::class
Copy after login

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');
Copy after login

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();
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!