<?
if(!defined("__TriImage_class__")) {
define("__IriImage_class__",1);
class TriImageClass
{
/**********************************************************************************
TriImage Class -- written for PHP 3.x
by Kris Kumler
I have a lot of work to be done here, as you can tell. I should finish with this class
within a couple of weeks, but thought some people could get some use out of it...
mainly getTextyPos, which I will also add a much more simple set of function calls...
**********************************************************************************/
/* these functions are made to work for text that has an angle of 0
when i have time someday i'll change it to work with angles as well...
*/
var $defont;
var $defontSize;
var $deangle;
var $destring;
function TriImageClass() // constructor
{
$this->defont = "fonts/times.ttf";
$this->defontSize = 24;
$this->deangle = 0;
$this->destring = "Test";
}
/* function getImageWidth(...)
returns the total width that a true type font box requires
*/
function getTextWidth($font = -1, $fontSize = -1, $angle = -1, $string = -1)
{
if ($font == -1) { $font = $this->defont;}
if ($fontSize == -1) { $fontSize = $this->defontSize;}
if ($angle == -1) { $angle = $this->deangle;}
if ($string == -1) { $string = $this->destring;}
$imSize = ImageTTFBBox($fontSize,$angle,$font,$string);
$totalWidth = abs($imSize[4]-$imSize[0]);
return $totalWidth;
} // function getImageWidth
/* function getTextHeight(...)
returns the total height that a true type font box requires
*/
function getTextHeight($font = -1, $fontSize = -1, $angle = -1, $string = -1)
{
if ($font == -1) { $font = $this->defont;}
if ($fontSize == -1) { $fontSize = $this->defontSize;}
if ($angle == -1) { $angle = $this->deangle;}
if ($string == -1) { $string = $this->destring;}
$imSize = ImageTTFBBox($fontSize,$angle,$font,$string);
$upper = $imSize[5];
$lower = $imSize[1];
$totalHeight = abs($lower+$upper);
return $totalHeight;
}
/* function getTextxPos(...)
returns the approximate x position to use (to center) the text box.
*/
function getTextxPos($im = 0, $width = 0)
{
return abs(imagesx($im)-$width)/2;
} // function getTextxPos
/* function getTextyPos(...)
returns the approximate y position to use (to center) for the actual text box.
works well for multi-line messages with the ttf fonts I use
*/
function getTextyPos($im = 0, $height = 0)
{
return abs((imagesy($im) - $height))/2;
} // function getTextyPos
} // class TriImageClass
}
?> |