Thread Vertikale Spaltenbeschriftung für table (HTML) (72 answers)
Opened by bianca at 2010-08-01 20:39

bianca
 2010-08-02 13:47
#140232 #140232
User since
2009-09-13
6978 Artikel
BenutzerIn

user image
Ich kriegs nicht hin und bitte um Eure Hilfe.
Wenn ich den Modulnamen extra falsch schreibe kommt kristian's Lösung, das klappt auch.
Wenn ich den Modulnamen richtig schreibe bekomme ich am Ende in der DOSe/Win Vista/Strawberry ein "Out of Memory!". Das hatte ich noch nie?!
Wie implementiere ich das korrekt und vor allem wie bekomme ich meine Schriftartdatei eingebunden?
Die dejavusans.ttf liegt garantiert im selben Verzeichnis!

Danke

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/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 .= "<td>$ret</td>";
    $zeile .= "<td>$data{$string}</td>";
}

print $cgi -> header;
print $cgi -> start_html ('Test Hochkantschrift');
print <<HTML_TEIL;
<table>
    <tr><td>&nbsp;</td>$kopf</tr>
    <tr><td>Temperatur</td>$zeile</tr>
</table>
HTML_TEIL
print $cgi -> end_html;

sub hochkantschrift {
    my $return = join ('<br>',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;
}
10 print "Hallo"
20 goto 10

View full thread Vertikale Spaltenbeschriftung für table (HTML)