Image::Magick::NFPADiamond - This module renders a NFPA diamond using ImageMagick
use Image::Magick::NFPADiamond; my $diamond=Image::Magick::NFPADiamond->new(red=>3, blue=>0, yellow=>1); $diamond->save('warning.jpg');
This module composes a NFPA diamond or fire diamond image using ImageMagick perl module.
The constructor takes a series of arguments in a hash notation style, none of wich are mandatory:
The values to appear inside the red, yellow and blud diamonds. Should be a number, but any string would do.
The text to appear inside the white diamond. Any string would do. A
-W- has a special meaning and produces a strikethrough W to signal a hazardous material that shouln't be mixed with water.
JackDaniels is a synonim for this.
The size of the resulting image expressed as a single integer. The resulting image is always a square of size x size. If this argument is missing, a size of 320 is assumed.
The save() method writes the image to a specified argument. The argument may be a filename, but anything acceptable by ImageMagick should work.
The response method() writes the image to STDOUT. This is usefull for a CGI implementation (see the sample below). The argument is a ImageMagick format argument (like 'jpg','gif','png', etc).
Returns the underlying Magick image so it can be used as an element to another one
The diamond generation is done according to the following diagram:
All 4 text are scaled the same, based on the 'AAAA' string on 24px as a seed. This should cover strings like 'ALK', 'ACID'. A longer text will overlap.
The red and blue regions are colored using the ImageMagick provided 'red' and 'yellow' colors. The blue region is '#0063FF' to get a lighter tone.
This script works both with PerlEx and Apache
#!perl #This Perl script will produce a dynamic NFPA alike diamond use strict "vars"; use strict "subs"; use CGI; use Image::Magick::NFPADiamond; my $request=new CGI; #Using $request->Vars allows for a query_string like 'red=1&blue=2' to work my $img=Image::Magick::NFPADiamond->new($request->Vars) || die "Fail\n"; print $request->header(-type=> "image/jpeg", -expires=>'+3d'); binmode STDOUT; $img->response('jpg');
http://www.imagemagick.org/script/perl-magick.php, the PerlMagick man page.
Erich Strelow <email@example.com>
Copyright (C) 2008 by Erich Strelow
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
This module is provided "as is". This is in no way a sanctioned nor official nor verified version of the NFPA standard.