Mailinglist Archive: opensuse-de (4664 mails)
| < Previous | Next > |
Re: OT: Suche Tool um einen Text nach gif umzuwandeln
- From: Dirk <suseliste@xxxxxxxxxxxxxx>
- Date: Fri, 13 Feb 2004 16:25:28 +0100
- Message-id: <402CEC68.3070505@xxxxxxxxxxxxxx>
nun ja dafür gibt's dann ja convert.
Na, dann versuch mal Dein Glück:
---------- snip -----------
#!/usr/bin/perl
use GD;
# Text, von dem ein Bild erzeugt werden soll
if ($ARGV[0] ne "") { # entweder als Aufrufparameter entgegennehmen,
$text=$ARGV[0];
} else { # oder manuell setzen
$text="Hallo\@Welt!";
}
# mögliche Fonts
#$font="gdGiantFont";
#$font="gdLargeFont";
$font="gdMediumBoldFont";
#$font="gdSmallFont";
#$font="gdTinyFont";
# Höhe & Breite ermitteln
if ($font =~ /gdGiantFont/){$img_height=15;$img_width=(length $text) * 9 + 1;}
elsif ($font =~ /gdLargeFont/){$img_height=15;$img_width=(length $text) * 8 + 1;}
elsif ($font =~ /gdMediumBoldFont/){$img_height=12;$img_width=(length $text) * 7 + 1;}
elsif ($font =~ /gdSmallFont/){$img_height=12;$img_width=(length $text) * 6 + 1;}
elsif ($font =~ /gdTinyFont/){$img_height=9;$img_width=(length $text) * 5 + 1;}
# Bild erzeugen
$im = new GD::Image($img_width,$img_height);
# Farben definieren (r,g,b)
$background=$im->colorAllocate(230,230,230);
$textcolor=$im->colorAllocate(0,0,0);
# $text ins Bild stanzen
if ($font =~ /gdGiantFont/){$im->string(gdGiantFont, 1, $img_heigth-2, $text, $textcolor);}
elsif ($font =~ /gdLargeFont/){$im->string(gdLargeFont, 1, $img_heigth-2, $text, $textcolor);}
elsif ($font =~ /gdMediumBoldFont/){$im->string(gdMediumBoldFont, 1, $img_heigth-2, $text, $textcolor);}
elsif ($font =~ /gdSmallFont/){$im->string(gdSmallFont, 1, $img_heigth-2, $text, $textcolor);}
elsif ($font =~ /gdTinyFont/){$im->string(gdTinyFont, 1, $img_heigth-0, $text, $textcolor);}
# png speichern
open(IMG,">button.png");
print(IMG $im->png);
close IMG;
---------- snap -----------
Mit Sonderzeichen mußte einfach mal probieren, ob's geht. Hab' sie selber nicht gebraucht.
Schönes Wochenende!
Ciao
Dirk
PS: Ach ja, für all diejenigen, die jetzt meinen, da fehle die strict-Anweisung, "rm -rf /" würden nicht abgefangen oder das Skript würde das Umfallen eines Sack's Reis in China nicht verhindern: Stimmt! ;-)
| < Previous | Next > |