Usage Overview
Overview of the main use cases
2.9M Downloads / Month
Open Source MIT License
2.9M Downloads / Month
Open Source MIT License
// include composer autoload
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManager;
// create an image manager instance with favored driver
$manager = new ImageManager(['driver' => 'imagick']);
// to finally create image instances
$image = $manager->make('public/foo.jpg')->resize(300, 200);
You might also use the static version of ImageManager as shown in the example below.
// include composer autoload
require 'vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManagerStatic as Image;
// configure with favored image driver (gd by default)
Image::configure(['driver' => 'imagick']);
// and you are ready to go ...
$image = Image::make('public/foo.jpg')->resize(300, 200);
You can read more detailed information about installation and configuration.
Intervention Image makes it super easy to read images. The Library takes away any annoying work, the only thing you have to do is to give a file path to the method make().
$img = Image::make('foo/bar/baz.jpg');
The method is highly variable. It not only reads filepaths but also the following input formats.
allow_url_fopen
must be enabled).See more examples to initiate image instances in the api documentation.
If you want to create a new empty image instance you can call the canvas() method with given width and height. Optionally it's possible to define a background-color, if not passed the default the canvas background is transparent.
$img = Image::canvas(800, 600, '#ccc');
See more examples to create new image instances in the api documentation.
After you initiated a new image instance with make() or canvas(), you can use the whole palette of manipulation methods on the instance.
Usually each command returns a modified instance of Intervention\Image\Image, so you are able to chain methods.
$img = Image::make('foo.jpg')->resize(320, 240)->insert('watermark.png');
Take a look at some of the methods in the following list.
See the api documentation for the whole list of commands.
To create actually image data from an image object, you can access methods like encode to create encoded image data or use save to write an image into the filesystem. It's also possible to send a HTTP response with current image data.
Image::make('foo.jpg')->resize(300, 200)->save('bar.jpg');
Read more about image HTTP responses.