Skip to content

Guide · Open source

How to use Intervention Image in PHP: install, resize and save

Updated · written with AI from the project's own documentation and checked against our catalogue data

Intervention Image is an open-source PHP library for creating, editing and composing images. It gives you one set of commands that works on top of GD, Imagick or libvips, so you do not have to learn each extension's own API. This guide shows you how to install it with Composer, pick a driver, and run a short example that reads, scales, watermarks and saves an image.

Intervention ImageIntervention/image · ★ 14.4k · MIT

Quick start

  1. 1Check your server. Confirm PHP 8.3 or newer, the Mbstring extension, and at least one of GD, Imagick or libvips are available.
  2. 2Install Composer. Make sure Composer is installed, since the library is added with it.
  3. 3Add the package. Run composer require intervention/image in your project folder.
  4. 4Create a manager. Call ImageManager::usingDriver() with the driver class you want, such as GdDriver::class.
  5. 5Read and edit the image. Use decodePath() to load a file, then call methods such as scale() and insert().
  6. 6Encode and save. Use encodeUsingFormat() to choose the output format and quality, then call save() with the output path.

What you need before you install Intervention Image

Intervention Image runs only in PHP. The library requires PHP 8.3 or newer, the Mbstring PHP extension, and one image processing extension: GD, Imagick or libvips. You also need Composer to add the package to your project.

The library is framework-agnostic, so it can be added to any PHP project that meets these requirements.

  • PHP 8.3 or newer
  • Mbstring PHP extension
  • GD, Imagick or libvips PHP extension
  • Composer

Install Intervention Image with Composer

Run the following command in your project folder to add the package with Composer.

composer require intervention/image

Choose a driver and create an image manager

Intervention Image uses a driver for the actual processing. You can choose GD, Imagick or libvips. The example below creates a manager that uses the GD driver. The same fluent methods work with the other drivers, so switching is mainly a change to the driver class you pass in.

The libvips driver is provided as a separate package, documented in the project's libvips driver repository.

  • GD Library: included in the list of supported image libraries
  • Imagick PHP extension
  • libvips, via the Intervention Image driver for libvips
use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver as GdDriver; $manager = ImageManager::usingDriver(GdDriver::class);

Read, resize, watermark and save an image

The example reads an image from a path, scales it to a height of 300 pixels, places a watermark in the bottom right corner, encodes the result as JPEG at quality 65, and saves it. Each step is one method call on the image object.

Paths such as images/example.webp are relative examples. Replace them with your own file paths.

  • decodePath() reads image data from a file path
  • scale(height: 300) resizes by height
  • insert() adds a watermark image with an alignment such as Alignment::BOTTOM_RIGHT
  • encodeUsingFormat() converts to a format such as Format::JPEG with a quality setting
  • save() writes the encoded image to disk
use Intervention\Image\ImageManager; use Intervention\Image\Drivers\Gd\Driver as GdDriver; use Intervention\Image\Alignment; use Intervention\Image\Format; $manager = ImageManager::usingDriver(GdDriver::class); $image = $manager->decodePath('images/example.webp'); $image->scale(height: 300); $image->insert('images/watermark.png', alignment: Alignment::BOTTOM_RIGHT); $encoded = $image->encodeUsingFormat(Format::JPEG, quality: 65); $encoded->save('images/example.jpg');

Where to learn more

The README points to the official documentation for the basics, including how to instantiate the library. The documentation is the place to look for the full list of methods beyond the ones in this guide.

If you find a security issue, the README asks you to email the maintainer directly rather than opening a public report.

  • Official documentation: image.intervention.io
  • Security issues: email the maintainer at the address listed in the README

What people use it for

  • Resizing user-uploaded photos on a PHP server before storing them
  • Converting uploaded images to JPEG at a set quality to reduce file size
  • Adding a logo watermark to images in a PHP web application
  • Building image generation features in PHP
  • Working with animated images, which the README says all drivers support

Frequently asked questions

Is Intervention Image free to use?

Yes. Intervention Image is licensed under the MIT License, as stated in the project's README. You can read the full license text in the LICENSE file in the repository.

What PHP version does Intervention Image need?

It requires PHP 8.3 or newer. It also needs the Mbstring PHP extension and one of the GD, Imagick or libvips extensions.

How do I install Intervention Image?

Install it with Composer by running composer require intervention/image in your project folder. The library is framework-agnostic, so this works in any PHP project.

Should I use GD, Imagick or libvips?

The README does not rank the drivers. It says you can choose the one that fits your environment, and the same fluent methods work across all three. Use whichever extension your server has installed.

Can I use Intervention Image outside PHP?

No. The library only runs in PHP, so it is not suitable for non-PHP projects.

What are alternatives to Intervention Image?

Projects listed as comparable include Imagine, Glide, the Imagick PHP extension itself, and the Intervention Image driver for libvips. Compare them on the features you need and the driver they use.

New agent skills, repos and AI tools — every week

The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.

Our verdict

Intervention Image suits PHP developers who need to resize, convert or watermark images on a server and may need to switch between GD, Imagick or libvips. It is MIT-licensed and documented, and it works in any framework that runs on PHP 8.3 or newer. If you are not writing PHP, or you need a finished image editor rather than code, pick a different tool.

Install options & downloads