GT::Image::Security - Using the GD module, creates an image with text.
use GT::Image::Security;
my $sec_image = GT::Image::Security->new( fonts_path => "/home/aki/public_html/fonts", text => "Hello World" ) or die $GT::Image::Security::error;
# some versions have gif, others png my $img_type = $sec_image->image_type();
print "Content-type: image/$img_type\n\n"; print $sec_image->image_data;
Creates an image with specified text with mild alterations to rendered text and background to reduce machine legibility. Whenever it can, it will attempt to use TrueType fonts as the internal fonts tend to be difficult to read and very limited in the number of transformations possible.
Creates a new security image handler with all options populated but does not initialize the image. While most option are set by default or automatically, certain behaviours can be forced quite easily by passing in a new value.
new will return undef if the GD module cannot be loaded. The exact details of the error can be retreived from $GT::Image::Security::error or through the normal GT::Base error function mechanism.
The following is a list of attributes that can be used to customize the output.
Required. The string to be rendered in the image.
Optional. Required only if TrueType support is desired, it should be the path to the directory that holds .TTF files.
Optional. Typically automatically calculated, setting this will force the image to the specified height. (Output will be clipped if not tall enough)
Optional. Typically automatically calculated, setting this will force the image to the specified width. (Output will be clipped if not wide enough)
Optional. Set to png/jpeg/gif if the output format is important. If GD does not support the rendering method for the type of image, image_data will return undef and an error will be set.
Optional. Arrayref of filenames to ignore when scanning fonts for reasons such as illegibility. By default, the settings have been configured to work with the Bitstream Vera selection of fonts.
Optional. The number of steps between 0..255 in relation to the brightness of a single colour channel. By default, it has been set to 5 as older GD modules only support 256 colours.
Optional. Typically automatically chosen, it will invert the colour selections so instead of dark colours for the foreground, brighter colours will be chosen instead. Similarly for the background, from bright, dark colours will be chosen instead.
Optional. Maximum number of pixels to randomly offset characters from ideal position along the horizontal axis.
Optional. Maximum number of pixels to randomly offset characters from ideal position along the vertical axis.
Optional. Only affects TrueType fonts, internal fonts will not use this feature. The maximum amount of random angular rotation for each character in the text.
Optional. Only affects TrueType fonts, internal fonts will not use this feature. This sets the base point size of the font.
Optional. Only affects TrueType fonts, internal fonts will not use this feature. The maximum amount of random deviation from the base_pt size for each chacter rendered.
Optional. Usually set automatically, this sets the number of times the obfuscate_image action will be called uon the image. The action randomly draws a line or a rectangle on the image to provide chaff for any attempt to use OCR type software to extract the text from the image.
Optional. The amount of extra pixel space that should be around the text.
Optional. Typically shouldn't be used. However, it may be useful in situations where you would like to reproduce the image. After image_data has been called, squirrel away the value of $obj->{display_chars} and it will contain all the settings to be able to regenerate the image's core parts. Note: it does not store colour information so while the positions and size of the image would be the same, the colours would be different.
Returns the type of image the module will attempt to produce. The results can be ``png'', ``gif'', and ``jpeg'', fit for inserting into a mimetype header.
If an error occurs in the testing or no rendering methods could be found, the function will return undef. The details on the error can be retrieved through $obj->error
Returns a scalar with binary data which comprise the image. The image type
can be preset via the ``image_type'' attribute or accertained by the
image_type()
method.
If an error occurs in the testing or no rendering methods could be found, the function will return undef. The details on the error can be retrieved through $obj->error
GD, http://stein.cshl.org/WWW/software/GD/
Aki Mimoto
Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com
Revision: $Id: Security.pm,v 1.3 2006/11/03 18:55:35 brewt Exp $