It’s a quick task to set up your desktop WordPress server to run ImageMagick
Recent versions of the local desktop WordPress server MAMP come with ImageMagick already installed. If you want to check out ImageMagick on a locally-hosted test site, enabling ImageMagick on MAMP is a one-keystroke process. (Granted, you will make some clicks before and after the keystroke. Just go with me here, folks. How often can you do anything in one-ish keystroke? We’re on course to the quickest How-To ever.)
We’re going to enable the IMagick PHP extension that talks to ImageMagick, by uncommenting a line in PHP’s configuration file.
Step-by-step
-
- Fire up your MAMP/WordPress installation
- Go to the MAMP webstart page. (Usually http://localhost:8888/MAMP/ There’s a link in the MAMP interface.)
-
- Click on “phpinfo” in the header of the webstart page.
- On the phpinfo page, look at “Loaded Configuration file”. It’s about the seventh item down from the top. There, you see the path to the currently loaded instance of php.ini. For me, it’s “/Applications/MAMP/bin/php/php7.1.1/conf/php.ini”.
-
- In Finder, navigate to the folder shown. Find php.ini and open it in your favorite text editor (TextWrangler or Text Edit or whatever you like). Make sure you are in the correct folder, looking at the correct php.ini. There are multiple directories with php.ini’s in MAMP. (By my count, you should be at 11 clicks, no keystrokes, at this point)
- In php.ini, scroll down to the line that says:
;extension=imagick.so
-
- It’s about line 540 or so in my php.ini. You might think of just searching for “imagick”, but hold on there. Nobody authorized the expenditure of extra keystrokes!
- Uncomment the line by deleting the semicolon (Plunk. There’s your keystroke!) The line will look like so:
extension=imagick.so
-
- Save the file. (From the menu! No keystroke!)
-
- Restart the MAMP servers and you’re done! (15 clicks, counting the one double-click as two. One keystroke.)
Now see if it works; metadata should be preserved
To check to see if it’s working, you can call phpinfo again and scroll down past the table part to the part of the page that’s divided into alphabetically-arranged sections. There should now be a section for IMagick. That tells you that the IMagick extension loaded.
The real, for sure, way to see that ImageMagick is working, is to find a test image that has metadata and upload it to your test site’s Media Library. Then place one of the resized versions of your test image in a post. Then, download the picture from a Preview. Now, look at the downloaded file it in an application that reads metadata. If your metadata is still there, then all is good and ImageMagick is working.
(Note: When you right-click and download your file, you should see dimensions in the filename, like “test_image-300×150.jpg”. The original image won’t have dimensions appended to its filename. The original image hasn’t been touched, so it will still have its metadata, ImageMagick or not.)
Another way to see that metadata is being preserved is to simply point your metadata-reading image browser (Photo Mechanic, Bridge, XnView, at al) at your uploads folder and look at the files. The path on my machine is /Applications/MAMP/htdocs/the_name_of_your_test_site/wp-content/uploads/some_year/some_month/
Not too different on a real server
The procedure to enable ImageMagick isn’t terribly different on a real ImageMagick/IMagick-equipped web server. Consult your hosting provider’s documentation.
Switch off and on
Once you have ImageMagick working, you can turn it off again by commenting that line in php.ini. Just put the semicolon back.
Experiment with image quality
With your on-and-off switchable ImageMagick installation working, you can experiment with how ImageMagick handles compression of your images, compared to GD. Every image responds somewhat differently to the JPEG process, so this is your-mileage-may-vary territory, but many people report both better image quality and smaller files with ImageMagick.
I’ll do a future post listing hosting providers that support ImageMagick. If you have a good or bad ImageMagick hosting experience, please let me know!