use strict;
use warnings;
use GD;

my $text = "Nach Hause gehen";

create_button($text, 'button.gif', gdLargeFont, 8, 10);

sub create_button
  {
  # Parameter uebernehmen
  my ($message, $filename, $font, $fwidth, $fheight) = @_;

  # neues Bildelement bauen, Hoehe und Breite sind vom Font abhaengig
  my $width = (length($text) + 1) * $fwidth + 3;
  my $height = 2 * $fheight + 4;
  my $img = new GD::Image($width, $height);

  # Farben allokieren
  my $white = $img->colorAllocate(0xFF, 0xFF, 0xFF);
  my $black = $img->colorAllocate(0, 0, 0);
  my $dk_grey = $img->colorAllocate(0x80, 0x80, 0x80);
  my $lt_grey = $img->colorAllocate(0xDF, 0xDF, 0xDF);
  my $grey = $img->colorAllocate(0xC0, 0xC0, 0xC0);

  # Button zeichnen mit Rand und allem Drumrum
  $img->fill(1, 1, $grey);
  $img->line(0, 0, $width-2, 0, $white);
  $img->line(0, 0, 0, $height-2, $white);
  $img->line(1, 1, $width-3, 1, $lt_grey);
  $img->line(1, 1, 1, $height-3, $lt_grey);
  $img->line($width-1, $height-1, 0, $height-1, $black);
  $img->line($width-1, $height-1, $width-1, 0, $black);
  $img->line($width-2, $height-2, 1, $height-2, $dk_grey);
  $img->line($width-2, $height-2, $width-2, 1, $dk_grey);
  # Button beschriften
  $img->string($font, $fwidth/2+2, $fheight/2-1, $message, $dk_grey);
  $img->string($font, $fwidth/2+1, $fheight/2-1, $message, $black);

  # Als GIF ausgeben
  open(OUTPUT, '>', $filename) or die "Cannot open $filename";
  binmode OUTPUT;
  print OUTPUT $img->gif;
  close OUTPUT;
  }