Install ImageMagick and GhostScript on Mac OS
March 21st, 2010 by Administrator    

While trying to find ways to convert PDF to Image using PHP I have cam across some really cool stuff and I would like to share my experience on getting this to work on my Mac Server.

After looking all around the web I found that there isn’t really any PHP extension that does PDF-Image conversion. But instead there is a really nice library called ImageMagick that does this. ImageMagick is an command line utility that runs on Unix and Windows. So, in order to get this into web application we need to use the exec() command within PHP to run shell commands. This works like a champ.

Now let’s get to the important part.

Step 1

Make sure that you have the latest version of Xcode already installed on your computer. At this time of writing, it  is version 3.2 that comes with Snow Leopard Server 10.6. This step is pretty important and make sure you don’t miss this. Why? Let me explain it to you in the next step.

Step 2

Now we need to install MacPorts, go to MacPorts website and get the latest version of MacPorts. Download the DMG package for Mac OS. Don’t download the source as it requires much more advanced  unix skills to get it installed and working right. Download, extract and follow the on screen instructions to install MacPorts. Click finish when done. MacPorts requires Xcode installed.

Step 3

Open Terminal in /Applications/Utilities and type in this command:

sudo port install ImageMagick

Then type in the password if asked. This will take a while, so please be patient. The port command downloads ImageMagick and many of its delegate libraries (e.g. JPEG, PNG, Freetype, etc.) and configures, builds, and installs ImageMagick automatically.

After installing ImageMagick, type in this command to test if ImageMagick is working.

convert logo: logo.jpg

Step 4

Now if you want to PDF/PostScript conversion you need to install GhostScript. ImageMagick uses GhostScript to read and write PostScript files.

While you are in Terminal, type this command:

sudo port install GhostScript

Then type in password if asked. This also takes a while, so grab a beer or something while you wait.

Step 5

Now having ImageMagick and GhostScripts installed, you can try to convert some of your PDF to Image. For example:

convert something.pdf something.jpg
convert -density 300 -antialias somefile.pdf somefile.jpg

Good luck, if you have any question please post in the comment section.

You might also be interested in:

Share your thought:

 
Web design by Phong Vu - All content posted on here is copyright by Phong Vu and its rightful owner.