707 0 0 0
Last Updated : 2025-04-28 21:48:40
In this snippet I will teach you how to optimize images using Intervention Image with laravel
In this snippet I will guide you throught all you need to optimize images in laravel using Intervention Image in laravel .
First Step: Install Intervention in your laravel project
1- install intervention using composer like this
composer require intervention/image
2- after you have install intervention image with composer, open config/app.php and the following lines.
In $providers add this line
Intervention\Image\ImageServiceProvider::class,
In $aliases add this line
'Image' => Intervention\Image\Facades\Image::class,
3- then publish configuration files like this
php artisan config:publish intervention/image
Second Step: configure apache to include gd.
when you get an error like gd not installed in this php version or imagick not installed in this php version
open xampp then open php.ini search for ;extension:gd then remove semi colon then restart apache .
Third Step: Optimize image in upload in the controller
you can use the intervention like this
use Illuminate\Support\Facades\File;
use Intervention\Image\Facades\Image;
$name = time().'-'.hexdec(\uniqid()).'.'.$image->getClientOriginalExtension();
$img = Image::make($request->file('image'));
$img->resize(80, 80, function ($constraint) { // change 80*80 to the pixels you want
$constraint->aspectRatio();
})->save(public_path($path . $name));
// OR
Route::get('/', function() {
$img = Image::make('foo.jpg')->resize(300, 200);
return $img->response('jpg');
});