ImageMagick is a powerful library to manipulate images, a PHP extension needs to be installed using Pecl. We always need to switch to every PHP version and install the package for that specific version.
First install the brew ImageMagic package:
brew install imagemagickThen install the php extension for every installed PHP version. The installation will ask you what the ImageMagick location is, hit enter to let the installer autodetect that location.
Please provide the prefix of Imagemagick installation [autodetect] : <enter>
Install ImageMagick for each installed PHP version:
sphp 8.4 && pie install imagick/imagick
sphp 8.5 && pie install imagick/imagickThis will automatically add the extension to php.ini.
Warning
It is possible that the extension for PHP 8.5 can not be loaded by default from the installed directory. You can fix this by altering the extension path in php.ini
vi $(brew --prefix)/etc/php/8.5/php.iniThe installation location of the zend extension is displayed on the screen after the pecl package is compiled. Copy it and use it on top of php.ini:
extension="/opt/homebrew/Cellar/php/8.5.4/pecl/20240924/imagick.so"These steps are only required when ImageMagick is updated with an existing PHP installation.
When ImageMagick is updated (through homebrew) PHP will start throwing errors since its Imagick module is compiled against an older version.
First edit the php.ini config files and remove the line
extension="imagick.so".
vi $(brew --prefix)/etc/php/8.4/php.ini
vi $(brew --prefix)/etc/php/8.5/php.iniReinstall ImageMagick for all PHP versions:
sphp 8.4 && pie install imagick/imagick --force
sphp 8.5 && pie install imagick/imagick --force