Olaf wrote:
Good work!!!
Found a way already to use it in the menu / title?
You refer on {title} or insiede PHPLayers MENU??
If {title} i did it, with a query on DB
new function.imagetext.php is
Code: Select all
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.text.php
* Purpose: creates graphical headlines
*
* Author: Christoph Erdmann <mail@cerdmann.com>
* Version: 26.11.2004
* Internet: http://www.cerdmann.com
*
* Changelog:
* 2004-11-28 New "html"-paramter to use additional HTML-attributes
* 2004-11-28 New "dynamic"-paramter recreates images without waste files
* 2004-11-26 Some Change in structure, better documentation, better error-handling
* 2004-11-25 Support for prehtml and posthtml
* -------------------------------------------------------------
*/
// Todo:
if (!isset($smarty->imagetextcount)) $smarty->imagetextcount = 0;
function smarty_function_imagetext($params, &$smarty)
{
if(isset($params['now'])){
if(isset($params['format']))
$format = $params['format'];
else
$format = '%Y-%m-%d %H:%M:%S %z';
$params['text'] = strftime($format,time());
}
if(isset($params['title'])){
global $gCms;
$params['text'] = strtoupper($gCms->variables[page_name]);
$query = "SELECT `content_name` FROM `".$gCms->config["db_prefix"]."content` WHERE ";
$query .= "`content_alias` = '".$params['text']."'";
$query .= " LIMIT 1;";
$dbresult = $gCms->db->Execute($query);
$params['text'] = " ";
while ($row = $dbresult->FetchRow()) {
$params['text'] = $row["content_name"];
}
}
### Voreinstellungen
// Config einlesen
$config = parse_ini_file('modules/ImageText/textcache/styles.ini',true);
$config['main']['folder'] = 'modules/ImageText/textcache/';
$config['main']['fonts'] = 'modules/ImageText/textcache/fonts/';
$config['main']['cache'] = 'modules/ImageText/textcache/cache/';
// Nur dieser Ordner muss ffentlich zug?lich sein
// Welcher Style soll verwendet werden
$style = $config[$params['style']];
// Params-Werte berschreiben style-werte (Den "text"-Wert aus Style herausnehmen)
foreach ($params as $key=>$value) if ($key != 'text') $style[$key] = $value;
// Fehlerhafte Eingaben abfangen
if (empty($params['text'])) { $smarty->trigger_error("imagetext: missing 'text' parameter"); return; }
if (empty($params['style'])) { $smarty->trigger_error("imagetext: missing 'style' parameter"); return; }
if (empty($style['font'])) { $smarty->trigger_error("imagetext: missing 'font' parameter"); return; }
if (empty($style['size'])) { $smarty->trigger_error("imagetext: missing 'size' parameter"); return; }
if (empty($style['bgcolor'])) { $smarty->trigger_error("imagetext: missing 'bgcolor' parameter"); return; }
if (empty($style['fgcolor'])) { $smarty->trigger_error("imagetext: missing 'fgcolor' parameter"); return; }
if (empty($style['width'])) { $smarty->trigger_error("imagetext: missing 'width' parameter"); return; }
if (empty($style['height'])) { $smarty->trigger_error("imagetext: missing 'height' parameter"); return; }
// Welche Schrift soll verwendet werden
$font = $config['main']['fonts'].$style['font'];
// Hash des Textes sowie aller Paramter fr die Cache-Funktion
$hash = md5(implode('',$style).$params['text']);
// Die URL des zu erstellenden Bildes
$imgurl = $config['main']['cache'].$params['style'].'_'.$hash.'.gif';
// Die URL ?ert sich bei dynamischen Bildern
if (empty($style['fname'])){
if ($style['dynamic'] OR $style['dev'])
{
$hash = md5(implode('',$style).$smarty->imagetextcount);
$imgurl = $config['main']['cache'].$smarty->imagetextcount.'_'.$hash.'.gif';
$smarty->imagetextcount++;
}
}
else {
$imgurl = $config['main']['cache'].$style['fname'].'.gif';
}
### Bei Bedarf gecachtes Bild ausgeben
if (file_exists($imgurl) && $style['dev'] != true && $style['dynamic'] != true) return $style['prehtml'].'<img src="'.$imgurl.'" border="0" alt="'.$params['text'].'" '.$style['html'].' />'.$style['posthtml'];
### ansonsten neu erstellen
// Funktion, um aus Hex-Werten RGB-Werte zu gewinnen und einen Farb-Handler zurckzugeben
if (!function_exists('fromhex'))
{
function fromhex($image,$string) {
sscanf($string, "%2x%2x%2x", $red, $green, $blue);
return ImageColorAllocate($image,$red,$green,$blue);
}
}
### Zuersteinmal ein viermal so gro?s Bild erstellen, welches danach heruntergerechnet wird, um das Kerning zu verbessern
// Der Multiplikator. Je gr?r, desto besser das Kerning, aber desto langsamer das Ertellen
$multi = 4;
// Ausma? der Grafik ausrechnen
$bbox = imageftbbox ($style['size']*$multi, 0, $font, $params['text']);
$xcorr=0-$bbox[6]; // northwest X
$ycorr=0-$bbox[7]; // northwest Y
$box['left']=$bbox[6]+$xcorr;
$box['height']=abs($bbox[5])+abs($bbox[1]);
$box['width']=abs($bbox[2])+abs($bbox[0]);
$box['top'] = abs($bbox[5]);
// Nun das erste gro? Bild erstellen
$im = imagecreate ($box['width'], $box['height']);
$bgcolor = fromhex($im,$style['bgcolor']);
$fgcolor = fromhex($im,$style['fgcolor']);
imagettftext ($im, $style['size']*$multi, 0, $box['left'], $box['top'], $fgcolor, $font, $params['text']);
// Jetzt das gro? Bild heruntersamplen
if ($style['trim']) $ds = imagecreatetruecolor ($box['width']/$multi+$params['addx'], $style['height']);
else $ds = imagecreatetruecolor ($style['width'], $style['height']);
$bgcolor2 = fromhex($ds,$style['bgcolor']);
imageFill($ds,0,0,$bgcolor2);
imagecopyresampled($ds,$im,0,$style['y'],0,0,$box['width']/$multi, $box['height']/$multi,$box['width'], $box['height']);
imagetruecolortopalette($ds,0,256);
imagepalettecopy($ds,$im);
ImageColorTransparent($ds,$bgcolor);
// Wohin schreiben
ImageGIF ($ds,$imgurl);
ImageDestroy ($im);
ImageDestroy ($ds);
// und ausgeben
if ($style['dev']) $border = 1; else $border = 0;
return $style['prehtml'].'<img src="'.$imgurl.'" style="border: '.$border.'px solid #00ff00" alt="'.$params['text'].'" '.$style['html'].' />'.$style['posthtml'];
}
?>
for the other i don't now
