Install ImageMagick for IIS
ImageMagick is a popular bitmap image manipulation suite that is used for managing images for many web applications such as the PHP based Gallery 2, Coppermine and Qdig just to name a few. While PHP does have it's own image manipulation functionality with the GD library, it does come at the cost of performance (especially on larger images) and doesn't have quite the flexibility that the Imagemagick suite offers. In this guide we'll detail how to install ImageMagick on your Windows system so that it is available to IIS and your web applications that are able to use it.
There really isn't that much to installing ImageMagick so that it is available for IIS and your web applications, and basically comes down to setting permissions. One note of warning though is that to do this you must make the ImageMagick binaries executable by IIS, which is loosening your permissions and could potentially be a security issue. If you are using PHP there is an ImageMagick PECL dll that can be downloaded as part of the PECL package that should be more secure, however from my experience most PHP based photo album applications don't support this. Anyway, on with the guide.
1. Download and install
Obviously the first step is to get your hands on a copy of ImageMagick for Windows. Goto the download page at the ImageMagick site and choose your download. The "Q8" and "Q16" in the file names refer to how many bits per pixel the package offers. In most cases you'll select the 16 bit version, however if it consumes considerably more system resources so if you are planning on installing on a resource constrained system (such as a VPS) then you may want to consider the 8 bit version.
In this guide we'll be installing the "ImageMagick-x.x.x-x-Q16-windows-static.exe" file. Once you have downloaded it, install the program as you would any other. However I would suggest you do not place it in your normal program directory, and would strongly recommend you place it in a directory structure which has no spaces in the path.
2. Setting directory permissions
Once installed the next step is to set the permissions. To do this we'll use the cacls command line utility that comes with Windows as I've done before in my article on troubleshooting the Warning: exec() [function.exec]: Unable to fork PHP error. In this example I have installed ImageMagick in the root of my C drive in a directory called "IM". Lets first take a look at the default permissions attached to this directory by simply opening a command window and typing in cacls [directory path] and you should get similar results to below.
C:\>cacls IM
C:\IM BUILTIN\Administrators:(OI)(CI)F
NT AUTHORITY\SYSTEM:(OI)(CI)F
LAPTOP\Brashquido:F
CREATOR OWNER:(OI)(CI)(IO)F
BUILTIN\Users:(OI)(CI)R
BUILTIN\Users:(CI)(special access:)
FILE_APPEND_DATA
BUILTIN\Users:(CI)(special access:)
FILE_WRITE_DATAThe next step is to replace the permissions with only the very minimum you need to be able to use ImageMagick with IIS. Do do this you will need to assign the read & execute permissions to the IIS anonymous user account (assuming you are using the default IIS user account for IIS). To do this type in the following command and substitute the "iusr_laptop" user for your own IIS user account (always in the form of IUSR_COMPUTERNAME).
C:\>cacls IM /C /G iusr_laptop:R
Are you sure (Y/N)?y
processed dir: C:\IMSelect yes when prompted and all the permission on your ImageMagick directory will be replaced with the one you specified. Once this is complete type in the first command again to see the current permissions and you should see something similar to below.
C:\>cacls IM
C:\IM LAPTOP\IUSR_LAPTOP:(OI)(CI)RYou can now see that all the previous permissions are gone and have been replace with the permissions you specified in your previous cacls command. Also be mindful that you will need to ensure that the data directory of your photo gallery application will need to modify permission set for the IWAM_COMPUTERNAME account (IIS 5 & 5.1) or the NETWORK SERVICE account (IIS 6) in addition to your IUSR_COMPUTERNAME account so they are actually able to output data.
3. Setting cmd.exe permissions
One final thing you find you may need to do is also give access to IIS to execute the Windows command line interpreter which I have already covered in my article Warning: exec() [function.exec]: Unable to fork. Once again a word of warning with this as it does require giving IIS access to execute your command line interpreter which is a security risk (by default your IIS user account is explicitly denied access to cmd.exe).
Hopefully this guide has helped with getting ImageMagicK available to your IIS environment. As always any feedback or questions, please feel free to leave a comment here or post in the forums.
- 924 reads









Post new comment