Skip to content

Instantly share code, notes, and snippets.

@wozzup
Last active May 22, 2022 14:11
Show Gist options
  • Save wozzup/9793176 to your computer and use it in GitHub Desktop.
Save wozzup/9793176 to your computer and use it in GitHub Desktop.
Installing ImageMagick on Mac OSX for PHP and MAMP
Manual Installation
Install Ghostscript
Ghostscript is going to be doing the actual conversion for ImageMagick
`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.
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
pecl install imagick. Record the location of imagick.so when this command is finished.
Locate your php.ini file php --ini | grep "Loaded Configuration File.
Locate your extension directory cat /Applications/MAMP/bin/php/php5.3.6/conf/php.ini | grep extension_dir
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
If autoconf is missing: Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable ... then check for autoconf in /usr/bin or /usr/local/bin. If not present install autoconf : brew install autoconf Set $PHP_AUTOCONF variable:
export PHP_AUTOCONF=/usr/local/bin/autoconf
sudo ln -s /usr/local/Cellar/autoconf/2.69/bin/autoconf /usr/bin/autoconf
sudo ln -s /usr/local/Cellar/autoconf/2.69/bin/autoheader /usr/bin/autoheader
export PHP_AUTOCONF=/usr/bin/autoconf
Configure PHP to use imagick.so extension
Add this line into your php.ini file
extension=imagick.so
Test for success
Run the following to test for successful install. 1 should be printed if it finds the class.
php -r "print(class_exists('imagick'));"
Restart apache
Restart apache through MAMP.
Problems
PHP will not load extension or apache fails to start
Symbol not found: __cg_jpeg_resync_to_restart
Incompatible library version: libMagickWand-Q16.7.dylib requires version 14.0.0 or later
Comment out references to DYLD_LIBRARY_PATH in MAMP's environment configuration. This can have unintended consequences!
vi /Applications/MAMP/Library/bin/envvars
convert works from command line but not from apache
Postscript delegate failed
Make sure apache has access to ghostscript. See gs not in apache's environment path.
ln -s /usr/local/bin/gs /usr/bin/gs
https://github.com/delphian/drupal-convert-file/wiki/Installing-ImageMagick-on-Mac-OSX-for-PHP-and-MAMP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment