ImageMagick Brew installation with PHP Module in Mac OS X
Asked Answered
F

13

40

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

Fitzhugh answered 8/8, 2012 at 13:28 Comment(0)
O
32

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.

Orvalorvan answered 8/8, 2012 at 14:19 Comment(4)
Yeah, I did try that before, but that formula does not exist either. I tried: php-imagick, php5-imagick, imagick-php, imagick-php5...Fitzhugh
@WouterKonecny: try brew search imagick to find the exact name of the packge.Orvalorvan
use pecl install imagick to install PHP module for image magickDowzall
Scroll down to here for a suitable answer since php72 does not exist anymore on home-brew..Justin
D
49

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
Dancer answered 16/5, 2018 at 7:40 Comment(5)
if you encounter a "pkg-config not found" error after the "pecl install imagick" type "brew install pckg-config" and try againTunnage
@Tunnage I think there's a typo in that command - it seems there should not be a c in that command. What worked for me was brew install pkg-configPaganini
This one actually worked for me. I failed to get brew install php72-imagick working. so pecl install imagick is the right answer for me.Lucianaluciano
Works for PHP 8.1 too! ThanksHayashi
Thanks for sharing this set of steps. Worked a treat!Rubellite
P
45

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....

Pickens answered 17/4, 2013 at 16:0 Comment(5)
If 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 :pLectra
His name is Jose Gonzalez, he wasn't just a code monkey, he was one of us!Lectra
The 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?Pickens
Thanks, 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.Emee
not working now (homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.)Equinoctial
O
32

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.

Orvalorvan answered 8/8, 2012 at 14:19 Comment(4)
Yeah, I did try that before, but that formula does not exist either. I tried: php-imagick, php5-imagick, imagick-php, imagick-php5...Fitzhugh
@WouterKonecny: try brew search imagick to find the exact name of the packge.Orvalorvan
use pecl install imagick to install PHP module for image magickDowzall
Scroll down to here for a suitable answer since php72 does not exist anymore on home-brew..Justin
S
19

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
Shulins answered 30/11, 2014 at 11:8 Comment(0)
E
17

I had the same issue. These are the steps that worked for me if you are using php 5.6

  1. brew install php56-imagick
  2. brew install imagemagick
  3. 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 type
  4. php -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

Excreta answered 12/6, 2016 at 14:11 Comment(2)
Just saved my bacon again! Can't upvote again though otherwise I would xxRetiary
I 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.Goff
G
13

this one worked for me:

brew install imagemagick       # If it's not already installed
mkdir /usr/local/lib/php/pecl  # On my system this dir didn't exist and this caused pecl install to fail
pecl install imagick

here

Germanous answered 22/5, 2018 at 9:53 Comment(1)
This! (mkdir /usr/local/lib/php/pecl)Emanuel
F
4

Try:

brew install homebrew/php/php53-imagick
Forbis answered 3/2, 2016 at 17:9 Comment(0)
P
4

I've looking for correct way to install imagick on Mojavie and found solution that fully worked.

  1. brew install imagemagick@6
  2. brew install [email protected]
  3. Install headers (Xcode-select --install)
  4. Download imagick source code from: https://pecl.php.net/package/imagick
  5. Open terminal and enter unzipped folder imagick-3.4.3/imagick-3.4.3 (in my case)
  6. Run command phpize
  7. ./configure
  8. make

And now if error occurs like MagicWand not found, edit file Makefile and look for CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/. Inspect if in include folder there is no other folder. In my case it should be like this: CPPFLAGS = -I/usr/local/opt/imagemagick@6/include/ImageMagick-6

save and return to terminal and type make (after finished) sudo make install

imagick.so is located in imagick-3.4.3/imagick-3.4.3/modules

Paulie answered 12/4, 2019 at 16:52 Comment(1)
You 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)Farr
E
2

Ok after 1 hour at this I have figured it out. The mac is not giving the pecl script permissions to make a PHP directory. To resolve do as follows.

brew install imagemagick
Sudo pecl install imagick .  
php --ini | grep "Loaded Configuration File"
Add extension=imagick.so under extensions.

The install will be complete. Then, to test run:

php -r "print(class_exists('imagick'));"
Eudiometer answered 8/6, 2018 at 14:25 Comment(0)
I
0

From: php error: Class 'Imagick' not found

Did you add extension=imagick.so to your php.ini (or /etc/php.d/imagick.ini) file?

Infuse answered 8/8, 2012 at 13:41 Comment(7)
I have added extension=imagick.so to my php.ini file in /etc/php.ini and did a sudo apachectl restart. Still not working.Fitzhugh
You can verify via <? phpinfo() ?> if ImageMagick is loaded or not. Are you sure of which php you are using?Tick
Yes, version 5.3.13 is shown in phpinfo(). The module does not seem to be loaded, how to fix this?Fitzhugh
I 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.Fitzhugh
Well this seems to be your last option: https://mcmap.net/q/121160/-imagemagick-and-os-x-lion-trouble The link also features the commands to download and compile it directly.Tick
That 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.Fitzhugh
I want to confrm that @frankHag solution works for me. ThanksTelevision
V
0

I had the same error having already installed imagemagick and php71-imagick.

brew upgrade imagemagick - did the trick for me.

You may need sudo:

sudo brew upgrade imagemagick

You may need to restart apache / php-fpm / <other webserver>.

Visitation answered 19/3, 2018 at 18:24 Comment(0)
H
0

I cannot add comments because of reputation, but to add to this anwser:

answered Apr 12 at 16:52

Grzegorz Miśkiewicz

I was getting a missing php.h file, so as per Installing xdebug on MacOs Mojave - 'php.h' file not found I installed the necessary file via the below command:

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Hypethral answered 8/5, 2019 at 8:41 Comment(0)
D
0

I have installed the Magento 2 project and I want to run the catalog:image:resize command and our project image processing config is set to imagic(not php GD). enter image description here

Admin -> Stores -> Configuration -> Advanced -> Developer -> Image Processing Settings : imagic

I am using brew tap shivammathur/php to use the old php version with a brew package manager.

https://github.com/shivammathur/homebrew-php#install-php

I have followed this tutorial to install the required packages to use Imagic.

https://ma.ttias.be/install-phps-imagick-extension-on-mac-with-brew/

I have also verified php module list using php -m | grep -i magic

imagic is installed but php-imagic is not found.

enter image description here

But I found this file while running this command grep -rni "imagic" /usr/local/Cellar/[email protected]/7.4.33_4/

/usr/local/Cellar/[email protected]/7.4.33_4/include/php/ext/imagick/php_imagick_shared.h

I have run brew install php7.4-imagick and restart php. Then I have run brew install shivammathur/php/[email protected]. I have try many commnad like brew install php74-imagick and also search package for php74 but not found any usefull using brew search imagick this command.

Then I have run these command in sequence and it worked.

brew install imagemagick
brew install pkg-config
pecl install imagick
brew services restart [email protected]

Thank you.

Denticulation answered 5/9, 2023 at 9:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.