A GD library is needed.
$path=$modx->config['base_path'].'assets/plugins/text2image/'; //path
require_once($path.'text2image.php'); // the create image function
$e = &$modx->Event;
switch ($e->name) {
case "OnWebPagePrerender":
$o = &$modx->documentOutput; // get a reference of the output
$count_hits = preg_match_all('/\<h6\>(.+)<\/h6\>/',$o,$stored_hits); //look for all h6-tags and store them
for($i=0;$i<$count_hits;$i++) {
$filename = strip_tags($stored_hits[1][$i]); //stript additional tags in the h6-tag (like <strong>)
$filename = html_entity_decode($filename); //decode entities
$filename = urlencode($filename); //encode for proper filename (doesn´t work properly yet,or rather the call does´nt work for special chars)
$filenamefull = $modx->config['site_url'].'assets/plugins/text2image/images/'.$filename.'.gif'; // name and location of the image
$filepath = $path.'/images/'.$filename.'.gif'; //path to the image
if (file_exists($filepath)) { //is the image already created?
$o = str_replace($stored_hits[0][$i],'<img src="'.$filenamefull.'" />',$o); //...then show it (doesn´t work properly with special chars yet)
}
else {
text2image(strip_tags($stored_hits[1][$i]),$filenamefull) ; //...if there is no image: create it
}
// $o.= strip_tags($stored_hits[1][$i]).'<br />'.$stored_hits[0][$i].'<br />'.$count_hits.'<br />'.$filenamefull.'<br />'.$filepath.'<br />'.$check.'<br />'; //control output
}
break;
default :
return; // stop here.
break;
}
<?php
function text2image($text,$filenamefull) {
$text=html_entity_decode($text); //decode entities (otherwise entities will show up in graphic
$path=$modx->config['base_path'].'assets/plugins/text2image/images/';
$imgname = $path.'background_image.gif';
if(file_exists($imgname)) {
$im = @imagecreatefromgif ($imgname); // open background image if exists
} else
{ $im = imagecreate (350, 30); // ... or create one with the dimensions 350x30
}
$black = ImageColorAllocate ($im, 255, 255, 255); //background color
$white = ImageColorAllocate ($im, 142, 172, 213); // font color
ImageTTFText ($im, 16, 0, 0, 20, $white, $path.'xfiles.ttf',$text); // function, size, x, y, antialias, color, path to TTF file, text
$title= urlencode ($text); //make sensefull filename
ImageGif ($im,$path.$title.'.gif'); //create image and store it
ImageDestroy ($im);
?>
// ------------------------------------------------------------------------------------------------------------
// Snippet by pemacviper webmedia, www.pemacviper.de
// ------------------------------------------------------------------------------------------------------------
//
// This Snippet makes a PNG-Image out of the dynamic logtitle, pagetitle
// or description in every textcolor and backgroundcolor you want with or
// without shadow, with or without transparency.
// Just insert a new menu, the True Type Font you want and the PNG
// will be genereated and put into the page where you want it to be.
//
// Beware! True Type Fonts like "Times New Roman(R)" underlie Copyrights.
// Look for some FREE True Type Fonts in the net to be out of the wood.
// a good place to look is http://www.dafont.com/
//
// Configure the data below to make the snippet work.
//
// Have fun.
//
// This peace of code is free in the terms of the GNU GPL.
//
// ------------------------------------------------------------------------------------------------------------
// HISTORY
// ------------------------------------------------------------------------------------------------------------
//
// Ver. 1.3 Final - 23/10/2005 - pemacviper
// -added shadown function
//
// Ver. 1.2 Final - 18/06/2005 - pemacviper
// -XHTML-conform output
// -corporate-conform Snippetname(Makeimage > MakeImage)
//
// Ver. 1.1 Final - 17/05/2005 - Dimmy
// some small changes e.g. adding transparancy support
//
// Ver. 1.0 Final - 11/05/2005 - pemacviper
// authoring
//
// ------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------
// Start Configuration
// ------------------------------------------------------------------------------------------------------------
// Height and width of the pic
$height = "222";
$width = "140";
// Color of background in RGB, transparency from 0-127 (127=100%, 0=0%)
// Alpha transparancy added by Dimmy
$r1 = "255";
$g1 = "255";
$b1 = "255";
$tr1 = "0";
// Color of text in RGB, transparency from 0-127 (127=100%, 0=0%)
// Alpha transparancy added by Dimmy
$r2 = "43";
$g2 = "55";
$b2 = "140";
$tr2 = "0";
// Color of shadow in RGB, transparency from 0-127 (127=100%, 0=0%)
// Alpha transparancy added by Dimmy
$r3 = "200";
$g3 = "200";
$b3 = "200";
$tr3 = "0";
// Define her the image-text where "$text1" is the forground-text
// and "$text2" is the text of the shadown-text.
// If you don't want a shadow just leave "$text2" blank e.g. "$text2= "";"
// You can use here all the variables which are supported by Etomite e.g.
// "Pagetitle" of the site = $etomite->documentObject['pagetitle']
// "Longtitle" of the site = $etomite->documentObject['longtitle']
// "Description" of the site = $etomite->documentObject['description']
$text1 = $etomite->documentObject['pagetitle'];
$text2 = $etomite->documentObject['pagetitle'];
// Define here the name of the generated pic e.g.
// "Pagetitle" of the site = $etomite->documentObject['pagetitle']
// "Longtitle" of the site = $etomite->documentObject['longtitle']
// "Description" of the site = $etomite->documentObject['description']
$imgname = $etomite->documentObject['pagetitle'];
// Path where to save the pic
$imagepath = "assets/site/makeimage/images";
// Path to True Type Font where "$font1" is the font of the foreground-text
// and "$font2" is the font of the shadown-text.
$font1 = "/assets/site/makeimage/ttf/arial.ttf";
$font2 = "/assets/site/makeimage/ttf/arial.ttf";
// Define here the font size of the text and the shadow in px where
// "$fontsize1" is the size of the foreground-text and "$fontsize2"
// is the size of the shadow-text.
$fontsize1 = "25";
$fontsize2 = "25";
// Define here the rotation of the text and the shadow in degrees
// where "$rotate1" is the rotation of the foreground-text and "$rotate2"
// is the rotation of the shadow-text.
// "0" means text readable form left to right
// "90" means text readable from down to up
// "-90" means text readable from up to down
// "180" means text readable upsidedown
$rotate1 = "90";
$rotate2 = "90";
// Define here the distance from 0 on x-axis and y-axis of the text and
// the shadow in px where "$x1"/"$y1" is the position of the foreground-text
// and "$x2"/"$y2" is the position of the shadow-text.
$x1 = "90";
$y1 = "163";
$x2 = "120";
$y2 = "220";
// ------------------------------------------------------------------------------------------------------------
// End of Configuration
// ------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------
// Start Code
// ------------------------------------------------------------------------------------------------------------
Header ("Content-type: image/png"); // Generates the Header
$im = imagecreate ($width, $height); // Creates frame of pic
$backcolor = ImageColorAllocatealpha ($im, $r1, $g1, $b1, $tr1); // Creates back-color
$fontcolor1 = ImageColorAllocatealpha ($im, $r2, $g2, $b2, $tr2); // Creates shadown-text
$fontcolor2 = ImageColorAllocatealpha ($im, $r3, $g3, $b3, $tr3); // Creates foreground-text
ImageTTFText ($im, $fontsize2, $rotate2, $x2, $y2, $fontcolor2, $font2, $text2); // Shadowcreation
ImageTTFText ($im, $fontsize1, $rotate1, $x1, $y1, $fontcolor1, $font1, $text1); // Textcreation
ImagePNG ($im, "$imagepath/$imgname.png"); // Output of the pic
ImageDestroy ($im); // Clean the cache
return "<img src=\"$imagepath/$imgname.png\" border=\"0\" alt=\"$imgname\" />"; //Output for the Browser
// ------------------------------------------------------------------------------------------------------------
// End of Code
// ------------------------------------------------------------------------------------------------------------
I’m having trouble getting this to run. When I load a page with <h6> on I get the following error:
Parse error: parse error, unexpected $ in /home/orioscom/public_html/wip/ppps/assets/plugins/text2image/text2image.php on line 19
I’ve re-uploaded and re-created the php file several times, so I don’t think it’s a corrupt or incomplete upload.
While I’m here, how would I intergrate this with a DropMenu generated list menu?
Is anyone able to help with this one please?
Thanks!