#!/usr/bin/perl -w
use strict;
use diagnostics;
use warnings;
use CGI;
my $cgi = CGI -> new;
my %data = (
'New York' => 10,
'Madrid' => 25,
'Venezuela' => 35,
'Berlin' => 5,
);
my ($kopf,$zeile) = ('') x 2;
foreach my $string (keys %data) {
my $ret = hochkantschrift ($string,'dejavusans.ttf');
$kopf .= "
$ret | ";
$zeile .= "$data{$string} | ";
}
print $cgi -> header;
print $cgi -> start_html ('Test Hochkantschrift');
print <
| $kopf
Temperatur | $zeile
HTML_TEIL
print $cgi -> end_html;
sub hochkantschrift {
my $return = join ('
',split (//,$_[0])); # Default, falls bei der andere Variante etwas schief geht
do {{
my $modul = 1;
eval "use GD; 1;" or $modul = 0;
last if !$modul || !-f $_[1];
# my $font = GD::Font->Small;
my $font;
my $error = 0;
eval { # eval da das Modul sonst eine Fehlermeldung wirft falls etwas mit der Datei nicht stimmt
$font = GD::Font -> load ($_[1]) or $error = 1;
};
last if $error || !defined $font;
my $height = $font->height;
my $width = $font->width;
my $im = GD::Image->new($height,5 + $width * length $_[0]);
my $white = $im->colorAllocate(255,255,255);
my $color = $im->colorAllocate(0,0,0); # ist Schwarz
$im->transparent($white);
$im->stringUp($font,0,$width * length $_[0],$_[0],$color);
open my $file,'>','hochkantschrift.png';
binmode ($file);
print $file $im -> png;
$return = 1;
last;
}} while (0);
return $return;
}