Intervention Image Laravel is a powerful package for image manipulation in Laravel applications.
It lets you resize, crop, rotate, compress, optimize, and convert images using the PHP GD Extension.
Whether you’re building an eCommerce store or CMS, Intervention Image Laravel helps improve image quality and application performance.
It also reduces image sizes, speeds up page loading, and delivers a better user experience.
In this guide, you’ll learn how to install the GD Extension and configure Intervention Image Laravel step by step.
You’ll also discover how to process uploaded images, generate thumbnails, and optimize images with practical examples.
By the end of this tutorial, you’ll be able to use Intervention Image Laravel efficiently in your Laravel projects.
What is Intervention Image Laravel?
Intervention Image is a popular open-source PHP image handling and manipulation library.
It provides a simple and expressive API for working with images in Laravel and PHP applications.
With Intervention Image, you can:
- Resize images
- Crop images
- Rotate images
- Add watermarks
- Convert image formats
- Compress images
- Generate thumbnails
The package supports two image processing drivers:
- GD Library
- Imagick
The GD driver is the most commonly used because it comes bundled with PHP and is easy to install.
What is the Laravel GD Extension?
GD is a graphics library used to create and manipulate image files.
It enables PHP applications to perform operations such as resizing, cropping, drawing text, and dynamically generating images.
Intervention Image relies on either GD or Imagick to process images. If neither extension is installed, image manipulation features will not work.
How to Check if the Laravel GD Extension is Installed
Before installing Intervention Image, verify whether GD is already enabled.
Run:
|
1 2 |
php -m | grep gd |
Alternatively:
|
1 2 |
php -i | grep GD |
If GD is installed, you’ll see output similar to:
|
1 2 |
gd GD Support => enabled |
How to Install the Laravel GD Extension
Ubuntu/Debian
Install GD using:
|
1 2 3 |
sudo apt update sudo apt install php-gd |
For a specific PHP version:
|
1 2 |
sudo apt install php8.2-gd |
Restart your web server:
|
1 2 |
sudo systemctl restart apache2 |
Or for Nginx:
|
1 2 3 |
sudo systemctl restart php8.2-fpm sudo systemctl restart nginx |
CentOS/RHEL
Install the extension:
|
1 2 |
sudo yum install php-gd |
Restart Apache:
|
1 2 |
sudo systemctl restart httpd |
Windows
- Open your
php.inifile. - Locate:
|
1 2 |
;extension=gd |
- Remove the semicolon:
|
1 2 |
extension=gd |
- Save the file.
- Restart Apache or your local development server.
Verifying GD Installation
Run:
|
1 2 |
php -m |
You should see:
|
1 2 |
gd |
You can also create a PHP info file:
|
1 |
<?php phpinfo(); |
Open it in your browser and search for GD Support.
Installing Intervention Image Laravel
Install the package using Composer:
|
1 2 |
composer require intervention/image |
Verify installation:
|
1 2 |
composer show intervention/image |
Resize Images with Intervention Image
Import the Image Manager:
|
1 2 3 |
use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver; |
Create a manager instance:
|
1 2 |
$manager = new ImageManager(new Driver()); |
Read an image:
|
1 |
$image = $manager->read(storage_path('app/public/sample.jpg')); |
Resize the image:
|
1 |
$image->resize(300, 300); |
Save the image:
|
1 |
$image->save(storage_path('app/public/resized.jpg')); |
Upload and Resize Images in Laravel
Controller Example
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
use Illuminate\Http\Request; use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver; public function upload(Request $request) { $request->validate([ 'image' => 'required|image' ]); $manager = new ImageManager(new Driver()); $image = $manager->read($request->file('image')); $image->resize(800, 600); $filename = time().'.jpg'; $image->save(public_path('uploads/'.$filename)); return back()->with('success', 'Image uploaded successfully.'); } |
Blade Form
|
1 2 3 4 5 6 7 8 9 10 11 |
<form action="{{ route('image.upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="image"> <button type="submit"> Upload </button> </form> |
Crop Images with Intervention Image
|
1 |
$image->crop(400, 400); |
This crops the image to a fixed size of 400×400.
Rotate Images in Laravel
|
1 |
$image->rotate(90); |
Rotate the image by 90 degrees.
Convert Image Formats with Intervention Image
Convert PNG to JPG:
|
1 |
$image->save('converted.jpg'); |
Intervention automatically determines the format based on the file extension.
Common Intervention Image Errors
GD Driver Not Installed
Error:
|
1 2 |
GD Library extension not available |
Solution:
Install and enable the GD extension, then restart your web server.
Class Not Found Error
|
1 2 |
Class "Intervention\Image\ImageManager" not found |
Solution:
|
1 2 3 |
composer install composer dump-autoload |
Memory Limit Errors
Large image uploads may exceed PHP memory limits.
Increase memory:
|
1 2 |
memory_limit = 512M |
Restart PHP afterward.
GD vs Imagick for Intervention Image
| Feature | GD | Imagick |
|---|---|---|
| Installation | Easy | Moderate |
| Performance | Good | Excellent |
| Memory Usage | Low | Higher |
| Advanced Features | Basic | Advanced |
| Laravel Compatibility | Excellent | Excellent |
For most Laravel projects, GD provides everything needed for image resizing and optimization.
Best Practices for Intervention Image
- Validate uploaded files before processing.
- Resize large images before storing them.
- Generate thumbnails for faster page loading.
- Store processed images in Laravel’s storage directory.
- Use queues for handling bulk image processing.
- Optimize image size to improve website performance.
Conclusion
Intervention Image is one of the best libraries for image manipulation in Laravel applications.
Before using it, ensure that the GD extension is properly installed and enabled on your server.
Once configured, you can easily resize, crop, rotate, and optimize images with minimal code.
By combining Laravel with Intervention Image and the GD extension,
developers can create powerful image-processing workflows while maintaining excellent application performance.
Also you can hire laravel developers to customize this feature for your business needs.
Kindly explore our extensions.