ImageMagick Brew installation with PHP Module in Mac OS X
Solution 1
Your ImageMagick installation is not enough. You also need the Imagick package (possibly called php72-imagick
or similar for home brew).
Imagick doesn't do the work itself, it is a native PHP extension for creating and modifying images using the ImageMagick API.
Try to search for the exact name of the package via brew search imagick
.
Solution 2
I just did this after a lot of experimenting. For now, this seems to be the way to do it for php 5.3:
brew tap josegonzalez/php
brew tap homebrew/dupes
brew install php53-imagick
No idea who Jose Gonzalez is but apparently we are in his debt....
Solution 3
php72-imagick
is now deprecated as imagick is part of php binary itself. Use pecl
to install imagick e.g.:
brew install php
brew install imagemagick
brew install pkg-config
pecl install imagick
Solution 4
I'm using Yosemite. For me, the solution is a combination of the answer and comment already listed here.
brew install imagemagick
brew install php55-imagick
Edit /etc/php.ini to include imagick
extension=/usr/local/Cellar/php55-imagick/{version of php55-imagick}/imagick.so
Example:
extension = /usr/local/Cellar/php55-imagick/3.1.2_1/imagick.so
Solution 5
I had the same issue. These are the steps that worked for me if you are using php 5.6
brew install php56-imagick
brew install imagemagick
find /usr/local/Cellar -name "imagick.so"
copy the path from the output of this command into your php.ini file
e.g.extension=/usr/local/Cellar/php56-imagick/3.3.0_2/imagick.so
save your file. Now to double check that the imagemagick class exists typephp -r "print(class_exists('imagick'));"
Brew symlinking wasn't working for me so I had to put the full pathname into the php.ini file to get it to work. Hope this helps
Wouter Konecny
I am a Software Engineer at a Dutch IT Company called Info Support.
Updated on November 16, 2020Comments
-
Wouter Konecny over 3 years
I have installed ImageMagick using
brew install imagemagick
. This all worked fine and I can run any ImageMagick command from the Terminal / Command line.Now when I try to use the ImageMagick classes in PHP, I get an error
Class 'Imagick' not found in ...
. I guess this is because the ImageMagick module is not loaded.Could anyone help me to get this thing working in PHP? Thanks!
Additional info:
Mac OS X Version: 10.8: Mountain Lion
PHP Version: 5.3.13 -
Wouter Konecny almost 12 yearsI have added
extension=imagick.so
to my php.ini file in/etc/php.ini
and did asudo apachectl restart
. Still not working. -
Jill-Jênn Vie almost 12 yearsYou can verify via
<? phpinfo() ?>
if ImageMagick is loaded or not. Are you sure ofwhich php
you are using? -
Wouter Konecny almost 12 yearsYes, version
5.3.13
is shown in phpinfo(). The module does not seem to be loaded, how to fix this? -
Wouter Konecny almost 12 yearsI have been searching for a while now and it seems that
brew install imagemagick
does not install the PHP Module. However,brew install imagick
does, but that formula is not (longer) available. -
Jill-Jênn Vie almost 12 yearsWell this seems to be your last option: stackoverflow.com/a/11661050/827989 The link also features the commands to download and compile it directly.
-
Wouter Konecny almost 12 yearsThat didn't work either, but thanks for your help! For now I will just do it the old-fashion way by compiling everything myself. I just hoped this would work with brew, as updating application (ImageMagick) versions is much easier that way.
-
Wouter Konecny almost 12 yearsYeah, I did try that before, but that formula does not exist either. I tried: php-imagick, php5-imagick, imagick-php, imagick-php5...
-
Kurt Pfeifle almost 12 years@WouterKonecny: try
brew search imagick
to find the exact name of the packge. -
a20 almost 11 yearsIf you could explain more about each step, it'd help everybody understand more .. I really appreciate your help here, but right now it's "giving us fish"; if you could take the time to "teach us to fish" also, that would be awesome :p
-
a20 almost 11 years
-
Admin almost 11 yearsThe two "brew tap" commands add repositories, or places where homebrew can look for packages. These two contain libraries and other requirements to get imagick working. Once you've registered those repositories with your copy of homebrew, it will know where to look for php53-imagick and anything marked as a requirement. Does that answer your question?
-
jarnoan almost 11 yearsThanks, this worked for me. I also had to manually add [imagick] extension="/usr/local/Cellar/php53-imagick/3.1.0RC2/imagick.so" in /etc/php.ini.
-
Friendly Code about 7 yearsJust saved my bacon again! Can't upvote again though otherwise I would xx
-
Deepak Bhatta about 7 yearsI want to confrm that @frankHag solution works for me. Thanks
-
EffectiX over 6 yearsI just used this same method for imagemagick on php 7.1 -- This is valid. Homebrew moved the ini file for the extension so php already picked it up. Step 4 was perfect to test it right away in cli.
-
Erwan almost 6 yearsif you encounter a "pkg-config not found" error after the "pecl install imagick" type "brew install pckg-config" and try again
-
Aftab over 5 yearsuse
pecl install imagick
to install PHP module for image magick -
HMagdy over 5 yearsnot working now (homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.)
-
MS Berends almost 5 yearsScroll down to here for a suitable answer since
php72
does not exist anymore on home-brew.. -
Jeff Puckett almost 5 years@Erwan I think there's a typo in that command - it seems there should not be a
c
in that command. What worked for me wasbrew install pkg-config
-
Tuhin over 3 yearsThis one actually worked for me. I failed to get
brew install php72-imagick
working. sopecl install imagick
is the right answer for me. -
Herz3h almost 3 yearsYou can also follow instructions on github.com/Imagick/imagick (must just make sure imagemagick is installed first before building the php extension, worked in my case on OSX Catalina using the linux instructions)
-
Sliq over 2 yearsWorks for PHP 8.1 too! Thanks