Craig Marvelley

Software and such

It’s a Kind of ImageMagick – Installing the PHP Extension for Windows 7.

I had a bit of a nightmare recently trying to get the ImageMagick PHP extension working on Windows. Builds of the extension as a DLL are provided by Mikko, which is awesome, but I had some trouble getting it to work.

The workstation I was using was running 64-bit Windows 7N, and the issue I was seeing was that the extension was being registered (if I ran php -m from the command line it seemed to be loaded) but when inspecting phpinfo() output the module was conspicuous by its absence.

Windows 7N is an EU version of Windows that comes without the Media Player framework – presumably an anti-trust related provision. Upon inspecting the extension DLL with Dependency Walker I discovered that it was linked to several missing DLLs that are supplied by the Media Player framework, and an additional DLL, IEShims.dll, which is an Internet Explorer library.

I installed the Media Feature Pack which resolved the majority of the missing DLLs. I also copied IEShims.dll from Program Files\Internet Explorer to Windows\SystemWOW64 (this probably wasn’t a good idea as the architectures of the DLLs will be fundamentally different, SystemWOW64 expects 32-bit DLLs – but I haven’t encountered any adverse effects as yet). After doing this the extension began to work as expected, and was visible in phpinfo() output.

There was a crucial comment on Mikko’s blog that I’ll repeat here – if the workstation is running PHP under IIS/FastCGI, install version 6.6.2-10 or earlier of ImageMagick (available from http://image_magick.veidrodis.com/image_magick/). Don’t install any versions later than that – they were built with VC10 and will not be compatible with the extension, which was built with VC9.

Finally, when I attempted to use the extension (I wanted to convert some images from SVG to PNG) I ran into errors because ImageMagick defaults to using the Windows temp directory as its conversion directory, and IUSR doesn’t have rights to write there. Rather than add it to the permitted users list (not a very secure approach) I set the IMAGICK_TMP environment system variable to a less prominent location; this required a restart to take effect.