Home arrow PHP arrow Security Images with PHP and ImageMagick

Security Images with PHP and ImageMagick

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.

TABLE OF CONTENTS:
  1. Security Images with PHP and ImageMagick
  2. The Image Generator
  3. The Form
  4. Conclusion
By: David Fells
Rating: starstarstarstarstar / 45
October 05, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Getting Started

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.



 
 
>>> More PHP Articles          >>> More By David Fells
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: