Install ImageMagick and imagick on Mac OS X Lion

If you’ve ever done any sort of image processing in your PHP applications, you’ll start to realise how limited you are when using native PHP commands such as createimagefromjpg etc. It eats your web servers memory! Nowadays, what with people carrying 5 Megapixel cameras in their phones, uploading and resizing a photo can be areal strain on resources, especially if several users on the website are doing it at the same time.

To get around this conundrum, there is a PHP library called imagick which allows you to access a program called ImageMagick. ImageMagick runs natively on the machine, and is available for Unix, Linux, Mac, and Windows, so running it shouldn’t be a problem. The only thing to take into consideration here is whether your hosting providers PHP has imagick available. If not, depending on your hosting package you may be able to SSH into your server and install it.

ImageMagick can do all sorts of crazy image editing things, and can handle pretty much whatever you throw at it! Find out more here:

Anyway, looks good, so let’s get cracking! If you have been following my posts you’ll see I upgraded my PHP from the old version that ships with Lion using ports. I’m also going to use ports to get ImageMagick.

sudo port install ImageMagick

This will take up to ten minutes! It gets all its dependencies, configures, and compiles from the source code specifically for your computer’s setup. Once it’s done there are several commands you can run from the terminal:


For more info see

Now that we’ve done that, we need to install the imagick PHP library that accesses it.
Depending on your luck this may work straight away for you:

sudo pecl install imagick

When it asks for the prefix, type it /opt/local.

If it fails to install, you are probably running PHP 5.4 like me. In this case, you need to tell pear to use the latest beta, which WILL compile.

sudo pear config-set preferred_state beta
sudo pecl install imagick
sudo pear config-set preferred_state stable

Last but least you should add “” to php.ini, and restart apache. Boom! now we have a very powerful tool for image manipulation!

Update: If you get this error – Please provide a path to MagickWand-config or Wand-config program.
Then – ensure “ImageMagick-devel” and NOT “ImageMagick” package is installed instead

9 thoughts on “Install ImageMagick and imagick on Mac OS X Lion

  1. You made some really good points there. I looked on the internet for more information about the issue and found
    most people will go along with your views on this web site.

    1. Thanks for your feedback!
      I should also point out for anyone who doesnt have pear and pecl installed that i have the instructions for that blogged on here somewhere too 🙂

  2. Marius says:

    Hey – thanks for this great tut. The first part worked like a charm, but I’m getting an error on the pecl part though : it goes through the motions of prepping the compile and then reports “ERROR: `/private/tmp/pear/temp/imagick/configure –with-imagick=/opt/local’ failed”. It’s probably a simple path issue, but I’m a bit clueless with the inner workings of compiling etc. I’m on Lion 10.7.4. Could you point me in the right direction?
    Many thanks!

    1. Derek McLean says:

      not sure amigo, if you dont have /opt/local, you could try making the folder!
      mkdir /opt/local

      also, I’ve literally just installed it on a Ubuntu server and a CentOS server. With the CentOS version, I had to install other packages before imagick would install:

      sudo yum install ImageMagick ImageMagick-devel ImageMagick-perl
      sudo pecl install imagick

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s