We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5004
    • 62 Posts
    Hi
    I try to use the snippet but I get this error:

    PHP error debug
    Error: imagettfbbox(): Could not find/open font
    Error type/ Nr.: Warning - 2
    File: /Library/Apache2/htdocs/demo/manager/includes/document.parser.class.inc.php(769) : eval()’d code
    Line: 84

    This is the snippet call:

    [[WriteWord?&file=`media/Ordnerin.ttf` &text=`[*pagetitle*]` &text_size=`26` &text_color=`#333333` &bg_color=`#FFFFFF` &quality=`100` &tpl=`writeword`]]

    I have uploaded the font in the media folder.
    The GD2 library is installed.
    The server is a Mac osx

    Any idea. Thank you.
      • 5004
      • 62 Posts
      Resolved smiley
      the problem was related to permission.
        • 12684
        • 118 Posts
        In the read me file it states
        The image will be duplicated with a hidden text that will be a search engine friendly.

        This is pretty straight forward, but how good is it? I mean how well will it do with SEO as opposed to using regular web safe font?
          • 10313
          • 375 Posts
          Hi, what a wonderful snippet smiley It works very good (for me).

          I’m wondering if it would be much work to buil a plugin that automatically converts all headlines to images, using this snippet. I have not done any plugin for now, so that’s why I’m asking. I only was into snippets so far.

          Greetings
          Martin

            • 10313
            • 375 Posts
            Ok, I know now that it (plugin) would work, but it is not too good for me to convert all H1 ...

            I have a different problem now: Snippet works great, BUT: it does not convert German Umlauts. I want the page title "Möbel" to be converted, but I receive "M bel" with a space instead of ö.

            Character encoding of the website is set to UTF-8. The font includes umlauts.

            Any idea anybody?
            Thanks
            Martin

              • 8522
              • 145 Posts
              Hi

              I tried to make a version (string2png) with letterspacing and wordspacing but with some fonts it didn’t look nicely. http://modxcms.com/forums/index.php/topic,30640.new/topicseen.html

              String2png can also do real alpha transparency. Now I ported this alpha-transparency-feature back to WriteWord. Hope it works for you and you like it smiley

              Here is the code.



              <?php
              //////////////////////////////////////////////////////////////////////////////////////////////////
              //
              // Snippet Name: 	WriteWord
              // Short Description:	This snippet allows to generate image from the text with any font
              // Version: 		0.25 ALPHA
              // Author: 		Metaller
              // Translator:		Igor
              // 
              //////////////////////////////////////////////////////////////////////////////////////////////////
              
              if (!isset($file)) return "Font file is not entered!";
              (isset($text)) ? $text : $text = "Text string is empty!";
              (isset($text_angle)) ? $text_angle : $text_angle = 0;
              (isset($text_size)) ? $text_size : $text_size = 14;
              (isset($text_color)) ? $text_color : $text_color = "#000000";
              (isset($bg_color)) ? $bg_color : $bg_color = "#FFFFFF";
              $scale = ($scale == TRUE) ? TRUE : FALSE;
              $format = strtolower($format);
              $format = ($format == "png") ? "png" : "jpg";
              $transparent = ($transparent == TRUE) ? TRUE : FALSE;
              (isset($quality)) ? $quality : $quality = 70;
              
              $ww_template = $tpl ? $modx->getChunk($tpl):  "<img src='[+ww.fileurl+]' width='[+ww.width+]' height='[+ww.height+]' border='0' title='[+ww.text+]'>";
              
              if (substr($text_color, 0,1) == "#") $text_color = substr($text_color, 1,6);
              if (substr($bg_color, 0,1) == "#") $bg_color = substr($bg_color, 1,6);
              
              $result = compact("file",  "text",  "text_angle",  "text_size",  "text_color",  "bg_color", "scale",  "format",  "transparent", "quality");
              
              foreach ($result as $k=>$v)
              {
              	$res[] = $k."=".$v;
              }
              
              $qry = implode("&", $res);
              
              $code = md5($qry);
              
              $filename=$modx->config['base_path']."assets/cache/{$code}.pageCache.{$format}";
              $fileurl = $modx->config['base_url']."assets/cache/{$code}.pageCache.{$format}";
              
              if (file_exists($filename)) 
              {
              	$size = getimagesize($filename);
              	$im_width = $size[0];
              	$im_height = $size[1];
              	
              	$ww_template = str_replace('[+ww.width+]', $im_width, $ww_template);
              	$ww_template = str_replace('[+ww.height+]', $im_height, $ww_template);
              	$ww_template = str_replace('[+ww.fileurl+]', $fileurl, $ww_template);
              	$ww_template = str_replace('[+ww.text+]', $text, $ww_template);
              		
              	return $ww_template;
              }
              
              
              if ($modx->config['modx_charset']!="UTF-8") $text = mb_convert_encoding($text, "UTF-8", $modx->config['modx_charset']);
              
              if (!extension_loaded('gd')) {
              	if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) {
              		@dl('php_gd2.dll');
              	}
              	else {
              		@dl('gd2.so');
              	}
              }
              
              $fontstmp= $modx->config['base_path']."assets/".$file;
              
              $text_font = sprintf("%s",$fontstmp);
              
              $box 		= imagettfbbox ( $text_size, $text_angle, $text_font, $text);
              $text_width	= $box[2]-$box[0];
              $text_height= $box[5]-$box[3];
              
              
              if ($scale)
              {
              	$text_size  = round((20 * $im_width)/$text_width);
              	$box 		= imagettfbbox ( $text_size, $text_angle, $text_font, $text);
              	$text_width	= $box[2]-$box[0];
              	$text_height= $box[5]-$box[3];
              
              	$text_x     	= ($im_width - $text_width)/2;
              	$text_y 		= ($im_height - $text_height)/2;
              }else{
              	$im_width = (isset($im_width))  ? $im_width : abs($text_width);
              	$im_height = (isset($im_height))  ? $im_height : abs($text_height);
              	$text_x     	= -$box[6]-1;
              	$text_y 		= -$box[7]-1;
              }
              if($transparent){
              $im_text 		= imageCreateTrueColor ($im_width, $im_height);
              imageSaveAlpha($im_text, true);
              imageAlphaBlending($im_text, false);
              $tlo = imagecolorallocatealpha($im_text, 220, 220, 220, 127);
              imagefill($im_text, 0, 0, $tlo);
              }else{
              $im_text 		= imagecreate ($im_width, $im_height);
              }
              
              $bg_r = hexdec(substr($bg_color, 0,2));
              $bg_g = hexdec(substr($bg_color, 2,2));
              $bg_b = hexdec(substr($bg_color, 4,2));
              
              $bgcolor 		= imagecolorallocate ($im_text, $bg_r, $bg_g, $bg_b);
              
              $text_r = hexdec(substr($text_color, 0,2));
              $text_g = hexdec(substr($text_color, 2,2));
              $text_b = hexdec(substr($text_color, 4,2));
              
              $textcolor 	= imagecolorallocate ($im_text, $text_r, $text_g, $text_b);
              
              imagettftext	(	$im_text,
              $text_size,
              $text_angle,
              $text_x,
              $text_y,
              $textcolor,
              $text_font,
              $text);
              
              if ($transparent) imagecolortransparent($im_text, $bgcolor);
              
              if ($format == "png")
              {
              	if (!file_exists($modx->config['base_path']."assets/cache/{$code}.pageCache.{$format}")) imagepng($im_text, $modx->config['base_path']."assets/cache/{$code}.pageCache.{$format}"); 
              }
              else
              {
              	if (!file_exists($modx->config['base_path']."assets/cache/{$code}.pageCache.{$format}")) imagejpeg($im_text, $modx->config['base_path']."assets/cache/{$code}.pageCache.{$format}",$quality); 
              }
              
              imagedestroy($im_text);
              
              if ($modx->config['modx_charset']!="UTF-8") $text = mb_convert_encoding($text, $modx->config['modx_charset'], "UTF-8");
              
              	
              $ww_template = str_replace('[+ww.width+]', $im_width, $ww_template);
              $ww_template = str_replace('[+ww.height+]', $im_height, $ww_template);
              $ww_template = str_replace('[+ww.fileurl+]', $fileurl, $ww_template);
              $ww_template = str_replace('[+ww.text+]', $text, $ww_template);
              	
              return $ww_template;
              ?>
                • 8522
                • 145 Posts
                Could somebody give me a working example of the scale option? I get some parser error sad

                [[WriteWord? &file=`media/somefont.ttf` &text=`foo`&scale=`TRUE`]]


                PHP error debug
                  Error: 	imagecreate() [function.imagecreate]: Invalid image dimensions	 
                  Error type/ Nr.: 	Warning - 2	 
                  File: 	/home/httpd/vhosts/mydomain.ch/subdomains/modxcms/httpdocs/manager/includes/document.parser.class.inc.php(772) : eval()'d code	 
                  Line: 	100
                  • 8790
                  • 526 Posts
                  Hi,

                  Thank you for your nice snippet.

                  Works fine, but:

                  The way you suggest to outputs the image in snippet comments (tpl part) is not so good, regarding an accessibility point of view

                  the default tpl coded into the snippet looks far better, except I suggest using the alt tag into the img (otherwise it’s not valid neither),
                  This is more useful than the title, because if images are disabled or text reading device read the text it’ll never find any text to read (afaik)
                  (title tag is quit unuseful in case of page title)

                  But I’m very confused by the tpl chunck for this output

                  if I use this into my tpl chunk
                  <img src="([+ww.fileurl+])"  width="[+ww.width+]" height="[+ww.height+]" alt="titre page:[+ww.text+]" title="[+ww.text+]" />

                  Nothing works huh

                  If I copy the harcoded one and adapt it using simple quote instead of double ", like this:
                  <img src='[+ww.fileurl+]' width='[+ww.width+]' height='[+ww.height+]' border='0' title='[+ww.text+]' />


                  It works undecided

                  So I just discovered img tag can be use with simple quote inside...

                  is this code is normal ?

                  Thank you

                    Schtroumpf Grognon - Grouchy Smurf
                    ---------------------------------
                    Faites pas attention.. - Don&#39;t pay attention
                    http://www.dzi-neo.net
                    • 473
                    • 70 Posts
                    Quote from: eerne at May 15, 2009, 05:02 AM

                    Could somebody give me a working example of the scale option? I get some parser error sad

                    [[WriteWord? &file=`media/somefont.ttf` &text=`foo`&scale=`TRUE`]]


                    PHP error debug
                      Error: 	imagecreate() [function.imagecreate]: Invalid image dimensions	 
                      Error type/ Nr.: 	Warning - 2	 
                      File: 	/home/httpd/vhosts/mydomain.ch/subdomains/modxcms/httpdocs/manager/includes/document.parser.class.inc.php(772) : eval()'d code	 
                      Line: 	100


                    I have the same problem
                      • 8790
                      • 526 Posts

                      Hi adhiarta,


                      I dont tried the scale option but, may be you must use the
                      width='[+ww.width+]' height='[+ww.height+]'
                      in your template isn’t it ?



                        Schtroumpf Grognon - Grouchy Smurf
                        ---------------------------------
                        Faites pas attention.. - Don&#39;t pay attention
                        http://www.dzi-neo.net