We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19164
    • 1,215 Posts
    Thanks for your report, Dimmy. I lost resource image parameter in imagepng function. You can download fix in my previous post.
      DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

      Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

      [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
      • 33540
      • 40 Posts
      Thank you Metaller but your link to fix_snippet it’s incorrect , archives is damaged .

        • 19164
        • 1,215 Posts
        I download it now and all is ok... Here is snippet code

        <?php
        //////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // Snippet Name: 	WriteWord
        // Short Description:	This snippet allows to generate image from the text with any font
        // Version: 		0.24
        // 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",  "im_width",  "im_height",  "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;
        }
        $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;
        ?>
          DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

          Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

          [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
          • 33540
          • 40 Posts
          Thank you very much .
            • 33540
            • 40 Posts
            I must surrender.  embarrassed

            I’m use  fix snippet and use snippet in my layout .

            How use snippet correctly ? sad

            My layout :


            <div class="title">
            [[WriteWord?&file=`media/lcallig.ttf` &text=`[*longtitle*]` &text_size=`14` &text_color=`#3C5E1B` &bg_color=`#E8ECD1` &quality=`100` ]]</div>
            <div class="metadata"></div>

            <div class="body">
            <div id="content">
            [[WriteWord?&file=`media/lcallig.ttf` &text=`[*#content*]` &text_size=`14` &text_color=`#3C5E1B` &bg_color=`#E8ECD1` &quality=`100` ]]

            [*#content*]
            </div>

            It’s efect

            http://utesi.pl/en/index_en.html
              • 19164
              • 1,215 Posts
              It seems that snippet not working with multiline strings. If there are linebreaks in &text parameter it is not working.

              When i coding this snippet i needeed only short single string and not tested on multilines. I’ll add this functionality in future if you need it.

              Now you can just remove empty lines near "under construction" and all must be ok.

              UPD Not sure, that multiline string functionality is realy needed in this snippet.
                DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

                Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

                [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
                • 33540
                • 40 Posts
                Thank you more time.
                I need this modyfication for my other sites, but I don’t must use this snippet , as it’s by fine .

                I wish you good night.

                ( my englis is horrible ) Next time ask my friend to translate .
                  • 19164
                  • 1,215 Posts
                  Problem is in MODx parser. It seems that linebreaks can’t pass through snippet parameters. And now i don’t know how to solve it.
                    DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

                    Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

                    [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    It would be a kludge, but how about making a wrapper snippet [[wrapper]] and in that snippet have a call to
                    $modx->runSnippet('WriteWord',array('param1'=>'value1', 'param2'=>'value2'...));

                    You would need to use the runSnippet call again if any of your parameter values are the result of other snippet calls
                    $modx->runSnippet('outerSnippet', array('param1'=>$modx->runSnippet('InnerSnippet', array('param1'=>'value1'))));

                    the parentheses get a little complex there!

                    http://wiki.modxcms.com/index.php/API:runSnippet
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 19164
                      • 1,215 Posts
                      Thank you, Susan. I am asking this question here too. So i think is better to wait for 0.9.7. wink
                        DirectResize 0.9 beta. PHPThumb, sets of configurations, configuration, binded to specific path. No backward compatibility. | DirectResize 0.9. PHPThumb, наборы параметров, параметры, привязанные к определенным путям. Без обратной совместимости.

                        Unfortunately, DirectResize project is closed. If you want to continue development, PM me for access to project page on Google Code. К сожалению, проект DirectResize закрыт. Если вы желаете продолжить разработки, обращайтесь через ПМ для получения доступа к репозиторию на Google Code.

                        [PLUGIN] DirectResize - as Maxigallery but for single images :: Download :: [url=http://modxcms.com/forums/index.php/topic,21490]