This article is intended to provide another look at Nathan Rohler's article that was recently published (the link is provided at the end of this article). His article illustrated how to use a database and PHP's image functions based on the GD library to create random security images. This article will demonstrate how to achieve the same goal (albeit with slightly different results) by using ImageMagick. I chose not to use hidden form fields and a database and instead opted for session variables, a much simpler and more efficient approach for our objective.
I chose to write this article using command line calls to the ImageMagick utility "convert". Most PHP users are developing websites on servers with virtual hosting packages and may not have the ability to use PHP with GD or ImageMagick support compiled in. While it is also possible that ImageMagick may not be available, it is highly unlikely that neither ImageMagick nor GD will be available to PHP users.
For those who can freely install software on their server, and for those who want to find out if they can use this code, there are a few pieces of software that must be installed. The usage of ImageMagick in this article requires that LIBPNG and TrueType are installed and that ImageMagick was compiled with support for them. If ImageMagick is already installed on your server, it is highly likely that it is set up in this manner. The plus to this is that if neither the GD nor the ImageMagick option is available to you, administrators are far more likely to install a utility like ImageMagick than to rebuild PHP on their server hosting hundreds of virtual sites to support GD.
There are a few differences in our capabilities when using ImageMagick vs using GD, the most noticeable of which has to do with handling fonts and text. GD is able to create a truetype textbox and return various properties about that box based on the font face and size assigned to it. In ImageMagick, there is no comparable feature. This limits our ability to position text on our background randomly. The problem is being unable to calculate how much space your text will occupy in a given font with a given size because ImageMagick only accepts font size in points. If you are familiar with typography, you will know that point size lends itself to unpredictable and arbitrary results on the web. If you choose to use a font other than the one I use in this article, you will most likely have to tinker with the range of text sizes to use.