All formats

Intervention Image

LanguagePHP 8.3 or later
LicenseMIT
Repositorygithub.com/Intervention/image
Documentationimage.intervention.io/v4
Depends onGD, Imagick or libvips (separate intervention/image-driver-vips package); the exif extension for metadata
Read / writeyes / yes; baseline and progressive, quality, optional metadata stripping; Exif reading

Intervention Image wraps PHP’s image extensions in one object-oriented API. You choose a driver (GD, Imagick or libvips) once; the rest of the code is the same. By default it applies the Exif orientation when it decodes a JPEG, reads Exif data into a collection you can query with dot notation, and encodes to JPEG, PNG, WebP, AVIF, GIF and other formats.

Version 4 (current) renamed the main entry points from version 3: ImageManager::usingDriver(), decodePath() instead of read(), encodeUsingFormat() instead of toJpeg(). Examples below use version 4.

Installation#

Shell
composer require intervention/image

Basic usage: resize a photo and save as JPEG#

PHP
<?php
require 'vendor/autoload.php';

use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\ImageManager;

$manager = ImageManager::usingDriver(Driver::class);   // or Drivers\Imagick\Driver

$image = $manager->decodePath('photo.jpg');   // auto-oriented by default
echo $image->width(), ' x ', $image->height(), "\n";

$image->scaleDown(width: 1200);               // keep aspect ratio, never upscale
$image->save('out.jpg', quality: 85);         // format from the file extension

How to encode a progressive JPEG#

PHP
use Intervention\Image\Encoders\JpegEncoder;

$encoded = $image->encode(new JpegEncoder(quality: 80, progressive: true, strip: true));
$encoded->save('out.jpg');
// or send it: header('Content-Type: image/jpeg'); echo $encoded;

strip: true removes metadata (driver support varies; it applies with Imagick and libvips).

How to read Exif data#

PHP
$image = $manager->decodePath('photo.jpg');
echo $image->exif('IFD0.Model'), "\n";
echo $image->exif('EXIF.DateTimeOriginal'), "\n";
print_r($image->exif('GPS'));    // section array

Exif is read with PHP’s exif_read_data, grouped by section (IFD0, EXIF, GPS, COMPUTED).

How to make square thumbnails#

PHP
$image = $manager->decodePath('photo.jpg');
$image->cover(300, 300);         // resize and crop to exactly 300x300, centered
$image->save('thumb.jpg', quality: 80);

How to turn off auto-orientation#

Driver options are passed to usingDriver:

PHP
$manager = ImageManager::usingDriver(Driver::class, autoOrientation: false, strip: true);

Tips#