ein Kunde wollte seine Hausschrift für die Headlines verwenden. Also hab ich mich an die Arbeit gemacht und so ein Ding erstellt und ihr sollt auch was davon haben!

Das Modul basiert auf dem Standard-Headline-HTML-Modul und benötigt noch eine PHP-Datei für die Funktionen und Konfiguration. Außerdem sollen noch zwei Verzeichnissse erstellt werden, eines in dem die Font (TrueType oder OpenType) liegt und eines für die generierten Bilder. Wurde schon das jeweilige Bild erzeugt, wird beim nächsten Aufruf das Erstellen des Bildes übersprungen (wg. der Perfomance).
Nochmal zur Übersicht:
Funktionen:
cms/includes/txt2img.php
Font:
cms/font/<fontdatei>
Zielverzeichnis der Bilder:
cms/images/headlines/
So, nun zur Installation:
Output:
Code: Alles auswählen
<?php
$editmode = ($contenido && ($view == "edit")) ? true : false;
include('includes/txt2img.php');
$headline = strip_tags("CMS_HTMLHEAD[1]");
$gimage = get_image($headline);
if (!$editmode)
{
echo '<img src="' . $gimage . '" border="0" />';
}
else
{
echo "CMS_HTMLHEAD[1]";
}
?>
Code: Alles auswählen
<?php
$fontsize = 14;
$fontname = 'bor';
$fontface = 'font/bor.ttf';
$aliasing = true;
$imagepath = 'images/headlines/';
$force_new_image = false;
function prepare_name($text)
{
global $fontname, $fontsize;
// simple char replace
$replace_array = array( ' ' => '_',
"'" => '',
'ä' => 'ae',
'ö' => 'oe',
'ü' => 'ue',
'ß' => 'ss',
' ' => '_',
'!' => '',
'.' => '',
',' => '',
':' => '',
'"' => '');
$imagefile = strtolower($text);
foreach($replace_array as $src => $dest)
{
$imagefile = str_replace($src, $dest, $imagefile);
}
// unique name according to fontface and size
return $fontname . '_' . $fontsize . '_' . $imagefile . '.png';
}
function get_image($rtext)
{
global $fontsize, $fontface, $aliasing, $imagepath, $force_new_image;
$new_file = $imagepath . prepare_name($rtext);
if(!is_file($new_file) || $force_new_image)
{
$box = imagettfbbox($fontsize, 0, $fontface, $rtext);
// get width of text from dimensions
$textwidth = abs($box[4] - $box[0]) * 1.03;
// get height of text from dimensions
$textheight = $fontsize * 1.4;
$im = imagecreate ($textwidth, $textheight);
$bga = imagecolorallocate($im, 246, 246, 246);
$fontcolor = imagecolorallocate($im, 121, 235, 44);
if(!$aliasing) $fontcolor = -$fontcolor;
imagettftext($im, $fontsize, 0, 0, $textheight * 0.8, $fontcolor, $fontface, escapeshellcmd($rtext));
imagepng($im, $new_file);
imagedestroy($im);
}
return $new_file;
}
?>

Grüße!