// 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(array('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(array('driver' => 'imagick')); // and you are ready to go ... $image = Image::make('public/foo.jpg')->resize(300, 200);
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().
Read image from file
$img = Image::make('foo/bar/baz.jpg');
The method is highly variable. It not only reads filepaths but also the following input formats.
- Path of the image in filesystem.
- URL of an image (
allow_url_fopenmust be enabled).
- Binary image data.
- Data-URL encoded image data.
- Base64 encoded image data.
- PHP resource of type gd. (when using GD driver)
- Imagick instance (when using Imagick driver)
- Intervention\Image\Image instance
- SplFileInfo instance (To handle Laravel file uploads via Symfony\Component\HttpFoundation\File\UploadedFile)
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.
Creating new images with background color
$img = Image::canvas(800, 600, '#ccc');
See more examples to create new image instances in the api documentation.
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.
Save an image in filesystem
Read more about image HTTP responses.