Skip to content

Installing ImageMagick on Mac OSX for PHP and MAMP

Bryan Hazelbaker edited this page Jun 6, 2013 · 25 revisions

Manual Installation

Install Ghostscript

Ghostscript is going to be doing the actual conversion for ImageMagick

  1. brew install ghostscript

If there is a failure try running brew update and then the command again.

Compile ImageMagick

ImageMagick must be compiled with ghostscript support to convert PDFs to images.

  1. brew install ImageMagick --with-ghostscript

After the above you should be able to execute convert -list delegate and see some entries for pdf.

Create PHP imagick.so extension

PHP will use ImageMagick through the extension imagick.so

  1. pecl install imagick. Record the location of imagick.so when this command is finished.
  2. Locate your php.ini file php --ini | grep "Loaded Configuration File.
  3. Locate your extension directory cat /Applications/MAMP/bin/php/php5.3.6/conf/php.ini | grep extension_dir
  4. Copy imagick.so into extension directory if its not already there (pecl may already have done it).

If you receive the error: php_imagick.h:40:10: fatal error: 'php.h' file not found then please reference: MAMP doesn’t ship with a bunch of the PHP sources

Configure PHP to use imagick.so extension

Add this line into your php.ini file

extension=imagick.so

Force MAMP to use system libraries

Only if you encounter errors such as Symbol not found: __cg_jpeg_resync_to_restart.

Comment out references to DYLD_LIBRARY_PATH. This can have unintended consequences!

  1. vi /Applications/MAMP/Library/bin/envvars
Ensure Apache has access to ghostscript

Only if convert runs fine from the command line but fails under php.

(http://stackoverflow.com/questions/588918/imagemagick-imagick-convert-pdf-to-jpg-using-native-php-api)

  1. ln -s /usr/local/bin/gs /usr/bin/gs

Clone this wiki locally