As part of my Statamic series, this post covers installing ImageMagick locally to process images, to get superior image quality on your sites.
You may be wondering “Why would I want to do this?” By default, like most CMS’s, Statamic generates images using software called “GD” (Graphics Draw). For most cases, this will probably be an OK default, but from my experience using ImageMagick as alternative image processing software generates superior images—especially with larger, more noticeable images.
Installing ImageMagick Locally
Even if you're comfortable getting ImageMagick installed on your production server, installing locally will likely be a different process.
driverand change the value to
Make sure you have homebrew installed. To check if you have homebrew installed, you can run
brew -v. If Terminal tells you the version number, then you're good to go. Otherwise, download homebrew from https://brew.sh/
brew install imagemagick. Check for any errors. At this point in the video, I was prompted to run a command to remove some leftover files.
brew install pkg-config
When prompted with
Please provide the prefix of Imagemagick installation [autodetect] :just hit enter.
Once complete try running
valet restartand refreshing your site. You'll know ImageMagick is successfully installed if 1) it generates Statamic Glide images correctly, and 2) if you go to
yoursite/cp/utilities/phpinfoyou should a new full section with the headline
imagick, with the first row of the section detailing the
imagick module version
In my experience development environment things seldom “just work”—there's either something you forgot to set or some error you need to deal with. While ImageMagick usually runs smoothly you'll see in the video I ran into an error. The good news is you can usually
Before you start searching for fixes it may be worth clearing the cache first with:
php please glide:clear
This didn't help the error I ran into—which in this case was:
warning: mkdir(): File exists in System.php on line 294
I eventually found an article by Patrique Ouimet, which detailed a fix—thank you, Patrique! https://patriqueouimet.ca/tip/installing-php-and-pecl-extensions-on-macos
In this case, you needed to run:
pecl config-get ext_dir | pbcopy
followed by pressing
cmd + v to paste the value you just copied to your clipboard.
Once this command has been run, and the directory has been created, try running
pecl install imagick again and maybe run
php please glide:clear to be on the safe side. Finally
valet restart and go back to your Utilities > PHP Info in your control panel. If everything's worked out, you should now see an Imagick section here.