Installing and using PHP ImageMagick (Imagick) Module

June 9, 2009

Image for Installing and using PHP ImageMagick (Imagick) Module from unsplash.com

Installation

On an Ubuntu System:

sudo apt-get install imagemagick libmagick9-dev php5-imagick php5-dev
wget http://pecl.php.net/get/imagick-3.0.0b1.tgz
tar xvfz imagick-3.0.0b1.tgz
cd imagick-3.0.0b1
phpize && ./configure
sudo make
sudo make install
sudo apache2ctl graceful

Example Usage:

<?php
//Create two Imagick objects
$first = new Imagick('tshirt.png');
$second = new Imagick('photo.jpg');
$first->compositeImage($second, Imagick::COMPOSITE_MULTIPLY, 220, 141);
//new image is saved as final.jpg
$first->setImageFormat('jpg');
header('content-type: image/jpeg');
echo $first->getImage();