#!/usr/bin/perl # If no background option is used then background color is transparent # blank. That means all blank pixels are transparent. # If no font option is used then gdLargeFont is used # If no foreground is used then black is used # If no width is used then string width is used # If no height is used then string height is used # If width option is too small then string width is used # If height option is too small then string height is used use GD; use Getopt::Long; GetOptions( "font=s" => \$font, "width=s" => \$width, "height=s" => \$height, "background=s" => \$wantedBackground, "foreground=s" => \$foreground, ); $font = ($font) ? &$font : gdGiantFont; $background = ($wantedBackground) ? $wantedBackground : "255 255 255"; $foreground = ($foreground) ? $foreground : "000 000 000"; $background =~ /\s*(\d{1,3})\s*(\d{1,3})\s*(\d{1,3})\s*/; ($rBackground, $gBackground, $bBackground) = ($1, $2, $3); $foreground =~ /\s*(\d{1,3})\s*(\d{1,3})\s*(\d{1,3})\s*/; ($rforeground, $gforeground, $bforeground) = ($1, $2, $3); foreach $string (@ARGV) { $stringLength = length($string); # The fonts # gdSmallFont, gdLargeFont, gdMediumBoldFont, gdTinyFont $pixelStringLength = $font->width * $stringLength; print "fw=", $font->width, " sl=$stringLength pl=$pixelStringLength\n"; $x = ($pixelStringLength >= $width) ? $pixelStringLength : $width; $y = ($font->height >= $height) ? $font->height : $height; $xOrigin = ($width) ? ($width - $pixelStringLength)/2 : "0"; $yOrigin = ($height) ? ($height - $font->height)/2: "0"; print STDOUT "($x, $y, $font , $xOrigin, $yOrigin, $string, $foreground, $background)\n"; $image = new GD::Image ($x, $y); $background = $image->colorAllocate($rBackground, $gBackground, $bBackground); ($wantedBackground) ? "" : $image->transparent($background); $foreground = $image->colorAllocate($rforeground, $gforeground, $bforeground); $image->string ($font , $xOrigin, $yOrigin, $string, $foreground); # Remove the blanks and &~'()@$£µ*%!#{}éèàù caracters $fileName = ${string}; $fileName =~ tr( &~'()@$£µ*%!#{}éèàù)(_________________eeau); $fileName .= ".png"; open FILE, ">$fileName"; print STDOUT "-> $fileName\n"; print FILE $image->png; close(FILE); } exit(0);