Simple page





Friday, 25 July 2014 00:00

Creating images from PDF with ImageMagick Library

Every once in a while we need to export an image from a pdf file either for personal use or just to display an image to a website. Of course the most common use about we see in the web sites is to automatically export the FrontPage of a pdf. But how is this possible really?

In this tutorial we will use the latest version of ImageMagic library (currently 6.8) in order to perform a conversion from pdf to image. It is important to note that ImageMagic needs to be installed to the server machine both as a library and apache module in order to work.

To start with we have to first install some required libraries.

yum install gcc php-devel php-pear
 sudo apt-get install gcc php-devel php-pear

Also it would be good to install / uninstall first the imageMagick from a repo list in order to get the dependencies like ghostscript.

We can do that by issuing in the command line:

yum install ImageMagick ImageMagick-devel
yum uninstall ImageMagick ImageMagick-devel


sudo apt-get install ImageMagick ImageMagick-devel
sudo apt-get uninstall ImageMagick ImageMagick-devel

After these steps we have to install the library itself.

cd /tmp
wget <a href=""></a>
tar xvzf ImageMagick-6.8.9-5.tar.gz
cd ImageMagick-6.8.9-5
make install

After the install is done we can also run "make check" in order to make sure everything is ok. Please note that this command tests every file type so it may take a while.

In order to install the image magic module for apache we must execute:

pecl install imagick
echo "" > /etc/php.d/imagick.ini

Followed by an apache restart

Service httpd restart

In order to test the script with php we can create an index.php file and we also need a pdf file named demo.pdf. You can find that script attached.

Have fun converting your pdfs !

Read 9672 times Last modified on Friday, 25 July 2014 14:44

Leave a comment