#!/usr/bin/perl use strict; use warnings; use GD; #Andrew Gaffney my $im = new GD::Image(61,20); my ($text, $saveto) = @ARGV || ('Hi There', $0.'.png'); my $white = $im->colorAllocate(255,255,255); my $black = $im->colorAllocate(0,0,0); my $gray = $im->colorAllocate(132,132,132); my $blue = $im->colorAllocate(206,206,255); my $leftblue = $im->colorAllocate(231,231,255); my $bottomblue = $im->colorAllocate(165,165,206); my $rightblue = $im->colorAllocate(123,123,156); my $topblue = $im->colorAllocate(214,214,255); $im->transparent($white); $im->interlaced('true'); $im->filledRectangle(0,0,60,19,$white); $im->filledRectangle(3,3,60,19,$gray); $im->filledRectangle(0,0,57,16,$blue); $im->rectangle(0,0,57,16,$white); $im->line(1,0,56,0,$topblue); $im->line(57,1,57,15,$rightblue); $im->line(1,16,56,16,$bottomblue); $im->line(0,1,0,15,$leftblue); # Dry run to determine size of outputted text #this requires libgd was compiled with TrueType Font support my (@bounds) = GD::Image->stringFT($black,"./Generic.ttf",9,0,0,0,$text); # Use above dimensions to center text $im->stringFT($black,"./Generic.ttf",9,0,((57 - $bounds[2])/2),13,$text); #$im->string(gdLargeFont, 2, 2, $text, $black); open IMAGE, "> $saveto" or die "Can't open $saveto\n"; binmode IMAGE; print IMAGE $im->png; close IMAGE;