use warnings; use strict; use GD; use GD::Text; use Color::Rgb; # Font you wish to use for this output image my $fontpath = '/usr/share/fonts/truetype/'; my $font = $fontpath . 'ttf-bitstream-vera/VeraSe.ttf'; my $fontsize = '10'; my $rgb = new Color::Rgb(rgb_txt=>'/usr/X11R6/lib/X11/rgb.txt'); # Create a new image my $width = 200; my $height = 200; # Allocate colors for rated levels # From: http://advogato.org/css/global.css my @advo = ( {name => 'Neophyte', color => '#c1c1c1', border => '#606060'}, {name => 'Apprentice', color => '#c0ffc8', border => '#008000'}, {name => 'Journeyer', color => '#c0d0ff', border => '#2040ff'}, {name => 'Master', color => '#e0d0ff', border => '#8000c0'}, {name => 'Undefined', color => '#e0d0c0', border => '#804020'}, ); for my $certs (@advo) { my $gd_text = GD::Text->new() or die GD::Text::error(); $gd_text->set_font($font, $fontsize) or die $gd_text->error; $gd_text->set_text($certs->{name}); my ($w, $h) = $gd_text->get('width', 'height'); my $im = new GD::Image($w+11, $h+6); my $x1 = 5; my $y1 = 15; $im->colorAllocate($rgb->hex2rgb("$certs->{color}")); my $black = $im->colorAllocate(0,0,0); my $color = $im->colorAllocate($rgb->hex2rgb("$certs->{color}")); my $border = $im->colorAllocate($rgb->hex2rgb("$certs->{border}")); my @bounds = $im->stringFT($black, $font, $fontsize, 0, $x1, $y1, $certs->{name}); $bounds[2] += 3; $bounds[3] += 3; $bounds[6] += -5; $bounds[7] += -5; $im->rectangle(@bounds[6,7], @bounds[2,3], $border); open(IMG, ">$certs->{name}.png") or die("Cannot open file!"); binmode IMG; print IMG $im->png; close IMG; }