geschrieben am 06.12.2007 | tags design, layout, php, tutorial, typo
Es gibt eine neue Version – mit mehr Performance und viel viel einfacher
Ihr braucht nichts anderes als die Glib und den folgenden Quellcode:
<?php
header('Content-type: image/png');
// Setup
$text = $g_text;
$fontfile = 'amiga.ttf'; // beliebiger TrueType Font
$fontsize = $g_fontsize;
$fontangle = 0;
// Ausmaße des Feldes ermitteln, den unser Text braucht evtl Anpassen
$textfield = imagettfbbox($fontsize, $fontangle, $fontfile, $text);
$text_size_x = (abs($textfield[4] - $textfield[0]) + 5);
$text_size_y = (abs($textfield[1] - $textfield[7]) + 5);
$text_pos_x = 0;
$text_pos_y = ($text_size_y - 2);
// Unser Arbeitsbild erstellen
$new_picture = imagecreate($text_size_x, $text_size_y);
// Farben bestimmen
$background_color = imagecolorallocate($new_picture, 68, 68, 68);
$text_color = imagecolorallocate($new_picture, 0, 106, 255);
imagefill($new_picture, 0, 0, $background_color);
imagettftext($new_picture, $fontsize, $fontangle, $text_pos_x, $text_pos_y, $text_color, $fontfile, $text);
// Hintergund transparent stellen
imagecolortransparent($new_picture, $background_color);
// Ausgabe des Bildes und anschliessende Löschung aus dem Speicher
imagepng($new_picture);
imagedestroy($new_picture);
?>
Das ganze speichert ihr als fontomat.php und fügt in eurem Header folgende PHP Funktion ein
<?
function fontomat($g_text,$g_fontsize)
{
echo"<imgsrc='fontomat.php?g_text=$g_text&g_fontsize=$g_fontsize' >";
}
?>
Wichtig hierbei ist das ihr umbedingt auf die Pfade achtet! Sonst funktioniert nichts und noch viel schlimmer ihr bekommt keine Fehlermeldung.
Um das ganze dann aufzurufen irgendwo im Dokument folgende Zeile eintippen
<?php fontomat("Mein Text",10); ?>
Hoffe das ganze ist ein wenig funktionaler als die alte Version. Der Ursprüngliche Quellcode habe ich hier gefunden. Danke.
Font-O-Mat
Redesign II
Neues Design III
fail week?