Configuration

Currently Intervention Image supports two Image processing extensions.

  • GD
  • Imagick

Make sure you have one of these installed in your PHP environment, before you start.

You’re able to configure Intervention Image to use one of these libraries for all its operations. Just pass the configuration as an array directly into the ImageManager.

Example

  1. // include composer autoload
  2. require 'vendor/autoload.php';
  3. // import the Intervention Image Manager Class
  4. use Intervention\Image\ImageManager;
  5. // create an image manager instance with favored driver
  6. $manager = new ImageManager(array('driver' => 'imagick'));
  7. // to finally create image instances
  8. $image = $manager->make('public/foo.jpg')->resize(300, 200);

You might also use the static version of ImageManager as shown in the example below.

Static Example

  1. // include composer autoload
  2. require 'vendor/autoload.php';
  3. // import the Intervention Image Manager Class
  4. use Intervention\Image\ImageManagerStatic as Image;
  5. // configure with favored image driver (gd by default)
  6. Image::configure(array('driver' => 'imagick'));
  7. // and you are ready to go ...
  8. $image = Image::make('public/foo.jpg')->resize(300, 200);

Configuration in Laravel

If you’re using Laravel, you can pull a configuration file into your application by running the following artisan command.

Publish configuration in Laravel 5

$ php artisan vendor:publish

Publish configuration in Laravel 4

$ php artisan config:publish intervention/image

In Laravel 5 applications the configuration file is copied to config/image.php, in older Laravel 4 applications you will find the file at app/config/packages/intervention/image/config.php. With this copy you can alter the image driver settings for you application locally and define which library should be used by all commands..

‘driver’ => ‘imagick’

Currently you can choose between gd and imagick support.


Memory Settings

Image manipulation in PHP is a very memory consuming task. Since most tasks in PHP don’t exhaust default memory limits, you have to make sure your PHP configuration is able to allocate enough memory to handle large images.

The following php.ini directives are important.

memory_limit

Sets a maximum amount of memory in bytes that a script is allowed to allocate. Resizing a 3000 x 2000 pixel image to 300 x 200 may take up to 32MB memory.

upload_max_filesize

If you’re planing to upload large images, verify that this setting for the maximum size of file uploads fits your needs.

Read more in the official PHP documentation for:

It’s possible to set these directives in your php.ini or at runtime with ini_set.