Skip to content
David Mongeau-Petitpas edited this page Feb 4, 2014 · 1 revision

The main difference between this package and other image manipulation libraries is that you can use parameters directly in the url to manipulate the image. A manipulated version of the image is then saved in the same path as the original image, creating a static version of the file and bypassing PHP for all future requests.

Alternatively, you can programmatically manipulate images using the Image::make($path,$parameters) method which returns an Imagine Image object. It also supports the same parameters as the Image::url($url,$width,$height,$parameters) method. To view the complete list of parameters, click here.

Manipulate the image with parameters in the url

For example, if you have an image at this URL:

/uploads/photo.jpg

To create a 300x300 version of this image in black and white, you use the URL:

/uploads/photo-image(300x300-crop-grayscale).jpg

To help you generate the URL of an image, you can use the Image::url($url,$width,$height,$parameters) function

Image::url('/uploads/photo.jpg',300,300,array('crop','grayscale'));

or

<img src="<?=Image::url('/uploads/photo.jpg',300,300,array('crop','grayscale'))?>" />

Manipulate the image programmatically

Use image parameters to easily manipulate the image

Image::make('/uploads/photo.jpg',array(
	'width' => 300,
	'height' => 300,
	'greyscale' => true
))->save('/path/to/the/thumbnail.jpg');

or use directly the Imagine library

$thumbnail = Image::open('/uploads/photo.jpg')
			->thumbnail(new Imagine\Image\Box(300,300));

$thumbnail->effects()->grayscale();
	
$thumbnail->save('/path/to/the/thumbnail.jpg');