This morning I attempted to migrate a fully working script from our test site to our production site. To my dismay, it stopped working on our production site.
The script used Imagick to composite two images together on the fly. It used WordPress for database connectivity by including wp-load.php.
Strangely, Firefox reported the image to be corrupt. I downloaded the image being generated and ran Imagick’s “identify” command against it via SSH. The tool reported the file had “two SOI markers” and “extraneous bytes before marker”. Exciting stuff.
After wracking my brain and starting the process of opening a StackOverflow post, a thought occurred to me: What if the problem is coming from WordPress. I threw together a quick proof of concept using Imagick and tested it. Worked fine. I then included wp-load.php at the beginning…corrupt image again.
At this point, I knew the problem was most likely a plugin. I realized that the only plugin difference between our test and production site was a plugin called WP-Minify that handles JS/CSS/HTML minification. I tried disabling it and magically the script worked again.
Unwilling to sacrifice the advantages of WP-Minify, I looked through the code. It turns out you can pass in wp-minify-off=1 as a URL parameter to any page to prevent it from processing. A very easy solution.
So there you go. That’s my story. If ImageMagick / Imagick is outputting a corrupt JPEG, and you are using WP-Minify, now you know how to solve it.

