Install ImgMagick for PHP on MacOS

Photo by Jess Bailey on Unsplash

Install ImgMagick for PHP on MacOS

·

1 min read

When it comes to image handling (from multiple things like crop, sizing,...). You won't use normal GD of PHP, it sucks.

You will use a library instead, and ImageMagick is quite awesome in terms of that.

From PHP, ImageMagick also offers a native extension for us to install. Which I'm about to show you below!!

I'll use brew and pecl for the installation.

Prepare

If you haven't installed this, run it:

brew install pkg-config zlib

Additionally, you might need to do this as well, in order to make the installation go smoothly.

ln -s /opt/homebrew/Cellar/pcre2/10.39/include/pcre2.h /opt/homebrew/Cellar/php/8.1.0_1/include/php/ext/pcre/pcre2.h

Install

brew install imagemagick
pect install imgmagick

If you see this "Extension imagick enabled in php.ini" after the command. Then congrats!