Using Intervention Image Package in Laravel for Image Manipulation
This article introduces the Laravel-compatible Intervention Image package, explains how to install it via Composer, configure the service provider and alias, and demonstrates basic image operations such as resizing, saving, and resource destruction, including a known issue with overwriting files.
Recently I discovered the Laravel-compatible image handling package intervention-image, whose documentation is at http://image.intervention.io.
Installation is straightforward: run composer require intervention/image in the project.
After installation, add the service provider Intervention\Image\ImageServiceProvider::class to the $providers array and the alias 'Image' => Intervention\Image\Facades\Image::class to the $aliases array in config/app.php. Then import the facade with use Intervention\Image\Facades\Image;.
Typical usage includes creating an image instance, resizing, and saving, e.g., $img = Image::make('public/foo.jpg')->resize(300, 200); followed by $img->save('public/bar.png');. If no path is supplied to save(), the original file is overwritten.
The package automatically destroys resources after the script ends, but you can also call $img->destroy(); to free memory manually. Note that when save() overwrites the original file, destroy() may not work as expected, while saving to a different file allows proper destruction.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
