<![CDATA[ Support/Comments for gtext - My Forums]]> https://forums.modx.com/thread/?thread=38300 <![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217008
I knew a good night’s sleep would do it.]]>
ooghe Oct 26, 2006, 08:08 AM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217008
<![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217007 doze Oct 25, 2006, 05:40 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217007 <![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217006 "config[’base_path’]."]]> ooghe Oct 25, 2006, 04:24 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217006 <![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217005
"config[’base_path’]."

with

"/var/www/vhosts/mysite/httpdocs/

The gtext seems to sort of not be messing up now, although it has yet to actually quite work... but I have renewed confidence.]]>
ooghe Oct 25, 2006, 03:23 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=3#dis-post-217005
<![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217004 http://modxcms.com/forums/index.php/topic,2647.30.html)- so I’ll give it a whirl:

Like others, I’m getting this error

« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »

PHP error debug
Error: imagettfbbox() [function.imagettfbbox]: Could not find/open font
Error type/ Nr.: Warning - 2
File: /httpdocs/manager/includes/document.parser.class.inc.php(705) : eval()’d code
Line: 208

Parser timing
MySQL: 0.0024 s s (3 Requests)
PHP: 0.0711 s s
Total: 0.0736 s s

with this call:

<img src="[[gtext? &font=`arial.ttf` &fontsize=`19` &color=`#aa3e00` &bgcolor=`#e6f4fb` &text=`Class Descriptions`]]" alt="Class Descriptions" />

I know my ttf is in the assets/fonts directory, backtics are being used, the file name is all lowercase in both instances... I’ve read all of the gtext thread as well as Text2PNG, and done a fair amount of gtext searching on the web.

- I’ve tried replacing assets/ paths with the full path "/var/www/vhosts/mysite/httpdocs/", to no avail
- I’ve tried replacing the offending line 208:

$bbox=imagettfbbox ($this->size, 0, $this->font, $tex);

with


$bbox=imagettfbbox(40,0,getcwd()."assets/fonts/arial.ttf","hi");

$bbox=imagettfbbox(40,0,getcwd()."fonts/arial.ttf","hi");

$bbox=imagettfbbox(40,0,getcwd()."arial.ttf","hi");

$bbox=imagettfbbox(40,0,getcwd()."arial","hi");

and done similar permutations with the actual call line

-I’ve checked done phpinfo and confirmed FreeType Support enabled (and MaxiGallery works fine)
-I’ve added .ttf as an allowable uploadable file in ModX, and re-uploaded arial.ttf
-I’ve set permissions to 777 on everything in every path, and created all the relevant directories- but nothing seems to work.

Does anyone have any clue what could be off?



]]>
ooghe Oct 25, 2006, 01:34 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217004
<![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217003 arphaus Sep 27, 2006, 03:11 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217003 <![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217002 Or is there an image in assets/images/gtext/gtext_daeca79880502eb41d393cdc165ceb32.gif ?

If you have many files with gtext_.. in assets/images you can move them to assets/images/gtext.


]]>
dazze Sep 27, 2006, 02:54 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217002
<![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217001
« MODx Parse Error »
MODx encountered the following error while attempting to parse the requested resource:
« PHP Parse Error »

PHP error debug
Error: fopen(/home/website/public_html/assets/images/gtext/gtext_daeca79880502eb41d393cdc165ceb32.gif): failed to open stream: No such file or directory
Error type/ Nr.: Warning - 2
File: /home/website/public_html/manager/includes/document.parser.class.inc.php(705) : eval()’d code
Line: 250

Parser timing
MySQL: 0.0459 s s (3 Requests)
PHP: 0.1641 s s
Total: 0.2100 s s

i removed the img tags as mentioned, here’s the various instances i’ve tried:

<h1><span class="graphicHeader">Class Descriptions</span><img src="[[gtext? &font=`BabelSans.ttf` &fontsize=`19` &color=`#aa3e00` &bgcolor=`#e6f4fb` &text=`Class Descriptions`]]" alt="Class Descriptions" /></h1>

<h1><span class="graphicHeader">Class Descriptions</span>[[gtext? &font=`BabelSans.ttf` &fontsize=`19` &color=`#aa3e00` &bgcolor=`#e6f4fb` &text=`Class Descriptions`]]</h1>

[gtext? &font=`BabelSans.ttf` &fontsize=`19` &color=`#aa3e00` &bgcolor=`#e6f4fb` &text=`New Code Test`]]
]]>
arphaus Sep 27, 2006, 02:13 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217001
<![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217000 arphaus Sep 27, 2006, 01:33 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-217000 <![CDATA[Re: Support/Comments for gtext]]> https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-216999

My Changes:
- possibility to use the snippet more than one time on a page
- changed the path to the gtext images (old: assets/images/ -> new: assets/images/gtext/
- snippet inserts the image (not printing the link), so you don’t need the img-tag around the snippet call


//GTEXT Snippet 
//Version 1.0, 30 january 2006
//Adrianus Warmenhoven

// patch by dazze 2006-09-27
// changes to original version marked with //#dazze#

//
//Used to create images out of text using a TrueType Font.
//usage:
//[[gtext?font=<fontname>&fontsize=<fontsize>&
//             color=<#color>&bgcolor=<#bgcolor>&
//             text=<usertext>]]
//
//This will then generate an image in '/assets/images/'
//and output the absolute path (when using as URL) to the 
//image.
//
//This is done so you can add your own HTML around it, or
//use it in other snippets.
//The font has to be uploaded in '/assets/files/fonts/'
//You have to create this directory and add .ttf to allowable
//uploadable files.
//
//Performance-wise it only generates some load once, since
//it creates a hash from all the parameters and uses that as
//the filename.
//If the parameters are the same, the file exists and only the
//path is returned.
//If the file does not exist, it is generated.
//You might have to clean the images directory once every so 
//often though... :)
//
//Based on the excellent atextimage class by George A. Clarke
//See license below.
//-----------------------------------------------------------
// class.atextimage.php
// version 1.1.0, 10 June, 2005
//
// License
//
// PHP class to put text of a True Type font onto a photo image, a graphic
// image or to create a new blank image with just the text.
//
// Copyright (C) 2005 George A. Clarke, [email protected], http://gaclarke.com/
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 59 Temple
// Place - Suite 330, Boston, MA 02111-1307, USA.
//
// Description
//
// This class allows for easy insertion of text onto an image. The image
// can be either an existing image file or a newly created blank image.
// If a new blank image is chosen, the class creates it, either the size you
// specify or will size it to exactly fit the text. You can have one line of
// text or multiple lines. Each cluster of lines of text can be positioned
// by top, center, or bottom, and left, center, or right. Each cluster of
// lines of text can be left, center, or right justified. There can also be
// multiple clusters of text on an image. This class uses True Type fonts
// which defaults to Arial.ttf and the size can also be set. The color of
// text can be specified, and the background color can also be specified
// if using a blank image.
// 
// This class would be good for adding comments onto photos in a photo
// gallery or to make dynamic navigation buttons on an html page.

// June,10, 2005: Added function SetOffset($offx,$offy)
//  Gave it the ability to offset from the chosen position up/down,
//  or left/right, by the specified number of pixels. This version is
//  backward compatible to the original one.

//#dazze# 
if(!defined("_class_aTextImage_")) {
define("_class_aTextImage_","1");
//#dazze# 

class ATextImage
{
  var $text = array();
  var $size;
  var $font;
  var $image;
  var $bgr;
  var $bgb;
  var $bgg;
  var $txtr;
  var $txtb;
  var $txtg;
  var $horz;
  var $vert;
  var $just;
  var $bdr;
  var $bdg;
  var $bdb;
  var $border;

 function ATextImage()
 {
//  Set default values for the class variables
  $this->size=12;             //font size
  $this->font="arial.ttf";    //path to True Type font file (.ttf)
  $this->bgr=255;             //background red color value (decimal 0-255)
  $this->bgb=255;             //background blue color value (decimal 0-255)
  $this->bgg=255;             //background green color value (decimal 0-255)
  $this->txtr=0;              //text red color value (decimal 0-255)
  $this->txtb=0;              //text blue color value (decimal 0-255)
  $this->txtg=0;              //text green color value (decimal 0-255)
  $this->horz="center";       //horiaontal position (left,center,right)
  $this->vert="center";       //vertical position (top,center,bottom)
  $this->just="center";       //text lines justification (left,center,right)
  $this->border=false;        //put border around image (true,false)
 }
//***************** User Functions ***********************
// $font >> Sets the path to the True Type font file.
// $size >> Sets the size of the font.
 function SetFont($font,$size)
 {
  $this->font = $font;      //path to the .ttf font file
  $this->size = $size;      //size of font
 }

// $bgr, $bgg, $bgb >> Sets the background color
// (red, green, blue) (0 - 255 decimal)
 function SetBackground($bgr,$bgg,$bgb)
 {
  $this->bgr=$bgr;          //red background value
  $this->bgb=$bgb;          //blue background value
  $this->bgg=$bgg;          //green background value
 }

// $bgr, $bgg, $bgb >> Sets the text color
// (red, green, blue) (0 - 255 decimal)
 function SetTextColor($txtr,$txtg,$txtb)
 {
  $this->txtr=$txtr;          //red text value
  $this->txtb=$txtb;          //blue text value
  $this->txtg=$txtg;          //green text value
 }

// Enables the border to be put around the image.
// $bgr, $bgg, $bgb >> Sets the border color
// (red, green, blue) (0 - 255 decimal)
 function SetBorder($bdr=0,$bdg=0,$bdb=0)
 {
  $this->border=true;
  $this->bdr=$bdr;          //red border value
  $this->bdb=$bdb;          //blue border value
  $this->bdg=$bdg;          //green border value
 }

// Sets the horizontal, vertical positions and the
//  justification of multiple lines of text.
// $horz >> should be left, center, or right
// $vert >> should be top, center, or bottom
// $just >> should be left, center, or right
 function SetPos($horz,$vert,$just)
 {
  $this->horz=$horz;         //horz=left,center,right
  $this->vert=$vert;         //vert=top,center,bottom
  $this->just=$just;         //just=horizontal justification
                             //     left,center,right
 }

 // Adds an x and y offset to the position settings.
 // x=positive >> offsets to the right
 // y=positive >> offsets down
 function SetOffset($offx,$offy)
 {
  $this->offx=$offx;
  $this->offy=$offy;
 }
 

// Adds one line of text to be inserted onto the image.
// $txt >> one line of text
// $clear >> should be true for the first line of a new group of text lines.
//           otherwise false.
 function AddLine($txt,$clear=FALSE)
 {
  if($clear)unset($this->text);
  $this->text[]=$txt;
  return $this->text;
 }

// Is called to load an existing image
// Can be .jpg, .png, or .gif
// $ipath >> path to image file (eg: c:\path\to\image\file\image.gif)
 function CreateImage($ipath)
 {
  $extn=explode(".",$ipath);
  $i=count($extn);
  $ext=$extn[$i-1];
  if($ext=="jpg")$this->image=imagecreatefromjpeg($ipath);
  if($ext=="png")$this->image=imagecreatefrompng($ipath);
  if($ext=="gif")$this->image=imagecreatefromgif($ipath);
 }

// Makes the new image with the text embedded
// If an existing image was not used, it creates a new blank one to use.
// $iw >> width of a new blank image
// $ih >> height of a new blank image
// If a new blank image is used and $iw and $ih are not specified or are zeros
//  the size of the new image will exactly fit the text.
 function MakeImage($iw=0,$ih=0)
 {
  $n=count($this->text);
  $tex=implode("\n",$this->text);
  $bbox=imagettfbbox ($this->size, 0, $this->font, $tex);
  $tww=$bbox[2]-$bbox[0]+2;
  $thh=$bbox[1]-$bbox[7]+1;
  $th=-$bbox[7]-1;
  $sp=($n>1)?$th+(($thh-($n*$th))/($n)):0;
  if(!$this->image)$this->image=imagecreate(($iw==0)?$tww:$iw,($ih==0)?$thh:$ih);
  $bgnd = imagecolorallocate($this->image,$this->bgr,$this->bgg,$this->bgb);
  $tclr = imagecolorallocate($this->image,$this->txtr,$this->txtg,$this->txtb);
  $bclr = imagecolorallocate($this->image,$this->bdr,$this->bdg,$this->bdb);
  $width=imagesx($this->image);
  $height=imagesy($this->image);
  $ynew=$this->Vert($height,$thh,$th)+($n-1)+$this->offy+1;
  foreach($this->text as $tx)
  {
  $bbox=imagettfbbox ($this->size, 0, $this->font, $tx);
  $tw=$bbox[2]-$bbox[0];
  $xnew=$this->Horiz($width,$tww,$tw)+$this->offx;
  imagettftext($this->image, $this->size, 0, $xnew, $ynew, $tclr, $this->font, $tx);
  $ynew=$ynew+$sp;
  }
 if($this->border)imagerectangle($this->image, 0, 0, $width-1, $height-1, $bclr );
}

// Displays and/or saves the new image with text as a gif image.
// $sim >> path for the saving of the new gif image with text.
// if $sim is not set, it will merely display the gif image with text.
// if $sim is set and $dim is set to 1, the image will be saved and displayed.
 function ShowGif($sim="",$dim="1")
 {
  //output picture
  header("Content-type: image/gif");
 if(!($sim=="")){
  $fh=fopen($sim,'w');
  fclose($fh);
  imagegif($this->image,$sim);
  }else{
  imagegif($this->image);
  }
  if($dim == "1")imagegif($this->image);
   imagedestroy($this->image);
 }

// Displays and/or saves the new image with text as a jpg image.
// $sim >> path for the saving of the new jpg image with text.
// if $sim is not set, it will merely display the jpg image with text.
// if $sim is set and $dim is set to 1, the image will be saved and displayed.
 function ShowJpg($sim="",$dim="1")
 {
  //output picture
  header("Content-type: image/jpeg");
 if(!($sim=="")){
  $fh=fopen($sim,'w');
  fclose($fh);
  imagejpeg($this->image,$sim,85);
  }else{
  imagejpeg($this->image,'',100);
  }
  if($dim == "1")imagejpeg($this->image,'',100);
   imagedestroy($this->image);
 }

// Displays and/or saves the new image with text as a png image.
// $sim >> path for the saving of the new png image with text.
// if $sim is not set, it will merely display the png image with text.
// if $sim is set and $dim is set to 1, the image will be saved and displayed.
  function ShowPng($sim="",$dim="1")
 {
  //output picture
  header("Content-type: image/png");
 if(!($sim=="")){
  $fh=fopen($sim,'w');
  fclose($fh);
  imagepng($this->image,$sim);
  }else{
  imagepng($this->image);
  }
  if($dim == "1")imagepng($this->image);
   imagedestroy($this->image);
 }

//**************** Internal Functions used by MakeImage**************
// Sets the horizontal position of the first character of a line of text.
// $width >> width of the image
// $twidth >> width of the longest line of this group of lines of text
// $lwidth >> width of this line of text.
 function Horiz($width,$twidth,$lwidth)
 {
  if($this->just=="right")$xnew=$twidth-$lwidth-2;
  if($this->just=="center")$xnew=($twidth-$lwidth)/2;
  if($this->just=="left")$xnew=1;
  if($this->horz=="right")$xnew=$xnew+($width-$twidth);
  if($this->horz=="center")$xnew=$xnew+($width-$twidth)/2;
  return $xnew;
 }

// Sets the vertical position of the first character of a line of text.
// $width >> height of the image
// $twidth >> height of this group of lines of text
// $lwidth >> height of one line of text.
  function Vert($height,$theight,$lheight)
 {
  if($this->vert=="center")$ynew=($height/2)-($theight/2)+$lheight;
  if($this->vert=="top")$ynew=$lheight;
  if($this->vert=="bottom")$ynew=$height-$theight+$lheight;
  return $ynew;
 }
}

//-----------------------------------------------------
function hex2rgb($hex) {
  $color = str_replace('#','',$hex);
  $rgb = array('r' => hexdec(substr($color,0,2)),
               'g' => hexdec(substr($color,2,2)),
               'b' => hexdec(substr($color,4,2)));
  return $rgb;
}//-----------------------------------------------------

//#dazze# 
}
//#dazze#

$usertxt="No text!";
if($text!=NULL)
{
 $usertxt=$text;
}
$userfont="arial.ttf";
if($font!=NULL)
{
 $userfont=$font;
}
$userfontsize=10;
if($fontsize!=NULL)
{
 $userfontsize=$fontsize;
}
$userfgcolor=hex2rgb("FF0000");
if($color!=NULL)
{
 $userfgcolor=hex2rgb($color);
}
$userbgcolor=hex2rgb("FFFFFF");
if($bgcolor!=NULL)
{
 $userbgcolor=hex2rgb($bgcolor);
}

$myfilename="gtext_".md5(base64_encode("text=".$usertxt."&font=".
              $userfont."&fontsize=".$fontsize."&fgcolor=".$userfgcolor.
              "&bgcolor=".$userbgcolor));
//#dazze#              
// original: if(!file_exists($modx->config['base_path']."assets/images/".$myfilename.".gif"))
if(!file_exists($modx->config['base_path']."assets/images/gtext/".$myfilename.".gif"))
   {
    $timg = new ATextImage();
    $timg->SetFont($modx->config['base_path']."assets/files/fonts/".$userfont,$userfontsize);
    $timg->SetBackground($userbgcolor["r"],$userbgcolor["g"],$userbgcolor["b"]);
    $timg->SetTextColor($userfgcolor["r"],$userfgcolor["g"],$userfgcolor["b"]);
    $timg->AddLine($usertxt);
    $timg->MakeImage();
    $timg->ShowGif($modx->config['base_path']."assets/images/gtext/".$myfilename.".gif",0);
   }
//#dazze#
// original: return "/assets/images/".$myfilename.".gif";
print "<img src='/assets/images/gtext/".$myfilename.".gif'/>";



]]>
dazze Sep 27, 2006, 01:09 PM https://forums.modx.com/thread/38300/support-comments-for-gtext?page=2#dis-post-216999