How to install ImageMagick for PDF and image processing on Ubuntu 12.04

ImageMagick is a set of open source softwares to manipulate images. (over 100 image file formats). In this tutorial we are going to install ImageMagick and capture a image from a pdf file with PHP.

To install ImageMagick run following commands:

apt-get install php5-dev
sudo apt-get install php-pear
sudo apt-get install imagemagick
sudo apt-get install libmagick9-dev
sudo apt-get install libmagickwand-dev libmagickcore-dev
sudo pecl install imagick

After installing ImageMagick, use this PHP code to capture first page of a pdf:

$img = new imagick(‘test.pdf[0]‘);
$img->thumbnailImage(300 , 417);  // width, height
$img = $img->flattenImages();
$img->setCompressionQuality(50); // Image quality
$img->writeImage(‘output.jpg’); //output

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>