1. Products
  2.   Image
  3.   PHP
  4.   Intervention Image
 
  

PHP Library for Image Manipulation & Processing

Open Source PHP Library that allows to Create, Read, Modify, Resize  & Crop JPEG, PNG, GIF, TIF, BMP, ICO, PSD, WebP images with ease.

Intervention Image is an open source PHP image manipulation and processing library that gives software developers the ability to create, modify, and compose images inside their own PHP application. Intervention Image has optional support for Laravel and comes with a Service Provider and Facades for easy integration. The library is very stable and helps you to manage every task in an easy way and with minimum code.

The library has provided support for the two most common image processing libraries GD Library and Imagick. It has provided support for many popular image file formats such as JPEG, PNG, GIF, TIF, BMP, ICO, PSD, WebP, and many more. The readable image formats depend on the chosen driver (GD or Imagick) and your local configuration.

The library has included support for several important image processing features, such as creating images from the scratch, reading existing images, editing existing images, creating image thumbnails, applying effects to images, adding watermarks to images, formatting large image files, resize images according to your needs, draw text and shape on images, retrieve image information and much more.

Previous Next

Getting Started with Intervention Image

It requires PHP 5.4+ with GD2 extension. The best way to install Intervention Image is quickly and easily with Composer. Please use the following command.

Install Intervention Image via Composer

$ php composer.phar require intervention/image 

Create New Images via via PHP

The open source Intervention Image library enables software developer to create a new empty image instance using PHP commands inside their own applications. Developers can provide custom width, height, and can also define a background color of their choice. If the color is not defined the default canvas background will be used which is transparent.

Create New Image & Get File Size via PHP

// create an image
$img = Image::make('public/foo.jpg');

// get file size
$size = $img->filesize();

Reading Images via PHP API

The Free Intervention Image library has provided support for reading different types of images inside JavaScript application with ease. You need to provide a complete path of the image and the rest will be easily performed by the library. You can also provide URL to the image and it can easily read it out for you. It can also read binary image data, base64 encoded image data, and more.

Cropping Image using PHP

The Intervention Image library has included functionality to programmatically crop images using a couple of lines of JavaScript code. The library allows developers to provide custom width and height of the rectangular part and cut out that part of the current image according to the provided width and height. Optionally you can also define the x, y coordinates to shift the top-left corner of the cutout to a particular location.

Crop Image via PHP

// open file a image resource
$img = Image::make('public/foo.jpg');

// crop image
'$img->crop(100, 100, 25, 25);

Using Image Filters

Filters are a bunch of commands that can emphasize certain features or remove other features. It gives you the useful option to group image transformation commands into a dedicated object and the object can be used to apply effects on an image. The object will define which command to use and in which order. The Intervention Image library also allows you to define your own filters and apply them with ease.

Apply Filter to Image via PHP

 namespace Intervention\Image\Filters;

class DemoFilter implements FilterInterface
{
    const DEFAULT_SIZE = 10;
    private $size;

    // Creates new instance of filter

    public function __construct($size = null)
    {
        $this->size = is_numeric($size) ? intval($size) : self::DEFAULT_SIZE;
    }

    public function applyFilter(\Intervention\Image\Image $image)
    {
        $image->pixelate($this->size);
        $image->greyscale();

        return $image;
    }
}
 English