Browsing articles tagged with " image magick"

Installing Image Magick and Imagick for PHP for MAMP

Jun 28, 2010   //   by the guru   //   Imagick, MAMP, PHP  //  7 Comments

Now this is one topic I am glad I have got through. This caused me no end of grief.

I think before we get to the nitty gritty of installing and configuring the software it is important to understand what Image Magick and Imagick are. I thought at first it was the same thing. Oh how wrong!

Image Magick is a command-line suite of tools to manipulate images. For further information on this visit the Image Magick site.

Imagick is an extension of PHP that consists of a number of classes and functions for working with Image Magick.

It basically means we need to install Image Magick first and then compile the Imagick extension in PHP that is dependent on Image Magick.

1. Installing MacPorts

To make life easy I installed MacPorts, which made it very easy to install Image Magick. You will need MacPorts in order to follow this post. Don’t worry if you haven’t installed MacPorts yet as you can find out how easy it is to install by viewing my “Installing MacPorts” post.

Please note that if you have Mac OS X 10.5.x or later you need to have Xcode 3.1.4 installed or later.

EDIT: Big thank you to Mike Puchol and his article Getting MAMP 1.9 to work with Image Magick, imagick.so and other flora for the next snippet for making MacPorts build universal binaries.

vi /opt/local/etc/macports/variants.conf

Add the following to the end of the file:

+universal

Save the file:

?wq

2. Installing Image Magick

Using MacPorts we simply need to enter:

sudo port install ImageMagick

Now I would suggest putting your feet up, grab something to eat, grab a beer or something else more interesting as this process takes about 30 minutes to finish. There are a number of dependencies that have to be installed.

Here’s One I Prepared Earlier…

Once that is all sorted you then need to update the environment $PATH variable in your user profile. To access your profile enter:

vi ~/.profile

Enter the following line:

export PATH="$PATH:/opt/local/bin"

For more information on this see “Updating Your Export Path in OS X”.

Close terminal and re-open it again. Then test Image Magick to see if it is working:

convert -version

If you get an error then there is a problem. Drop me a comment and I will see what I can do.

3. Now Installing The Tricky Imagick!

We now need to install the Imagick extension using PECL:

sudo pecl install imagick

Is that it I hear you say? Well let me tell you that it is at this point where I lost my rag given all the problems I had. I had got so lost I even nearly turned to the dark side and tried searching on Bing! To try and help I have added the issues I had and what I did to sort them.

A Make Error Occurs

I found this issue is likely to be down to the C compiler not being present. You will notice that there is an error relating to this, but it is right at the beginning of the make output. The easiest way to check if you have the C compiler is to type:

gcc

If you get a bash error then it is not installed. You can also check to see if the /usr/bin/gcc folder exists as that is where it should be.

So, to fix this issue you simply need to install the Xcode Tools. The quickest way to do this is on the installation disc that came with your Mac. It will be under the optional installs. If you can’t find the installation disc you can download the latest Xcode tools from the Apple Developer Connection site.

32bit and 64bit Architecture

As standard, MacPorts will not build universal binaries, which is what the PHP version run by MAMP uses. And as some versions of Mac OS X like Snow Leopard use 64bit architecture this can cause an issue. To get round this you can force MacPorts to build all the universal binaries by entering:

sudo port upgrade --force installed

Like installing Image Magick this will take a bit of time, so kick back and relax.

WARNING: php appears to have a suffix…

This is due to the PHP path being referenced twice or more in the environment variable $PATH. This is probably due to the /usr/bin and /Applications/MAMP/bin/php5.3/bin folders being present when they effectively point to the same place. You just need to remove the MAMP path. Restart terminal and you should be good to go. Don’t forget to check your $PATH enter:

echo $PATH

4. Are We There Yet?

Right, so the install of the Imagick extension has been successful. If so, you should see a message saying where the .so file was installed. You now need to copy that file over to the MAMP files:

cp /usr/lib/php/extensions/no-debug-non-zts-20060613/imagick.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/imagick.so

The above should be similar to yours, but will slightly differ, but you should be able to work it out.

The last bit then. We just need to add the new extension to the php.ini file. In MAMP select File -> Edit Templates and select the php.ini file you are using for your version. In the file add the Imagick extension:

extension=imagick.so

Apply the changes to MAMP, which should restart Apache and MySQL. Job done!!!

It has been emotional! This was a tough one, so if you need any help or have any suggestions just drop me some comments.