PHP
  Home arrow PHP arrow Security Images with PHP and ImageMagi...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Moblin 
JMSL Numerical Library 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Security Images with PHP and ImageMagick
By: David Fells
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 43
    2004-10-05

    Table of Contents:
  • Security Images with PHP and ImageMagick
  • The Image Generator
  • The Form
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Security Images with PHP and ImageMagick


    (Page 1 of 4 )

    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.

    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


       · In your $cmd commands, the -draw line is incorrect, or wouldn't work for me. If you...
       · hi,i copy and paste the code same as given in site..but dont know ..it doesnt...
     

       

    PHP ARTICLES

    - Building a Database-Driven Application with ...
    - User Authentication for a Project Management...
    - Introduction to the CodeIgniter PHP Framework
    - Adding Users for a Project Management Applic...
    - Migrating Class Code for a MIME Email to PHP...
    - Login and Logout Authentication for a Projec...
    - Composing Messages in HTML for MIME Email wi...
    - Project Management: Authentication
    - A Better Way to Determine MIME Types for MIM...
    - Project Management Overview
    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway