Forum Moderators: coopster
$o = new text2img("andreas");
$i = new text2img();
$o->showimage();
$i->showimage();
class text2img
{
var $t, $h, $w, $f, $x, $y, $tc, $a;
function text2img($text = "sample", $height = 19, $width = 11, $fontsize = 19, $x_axis = 0, $y_axis = 2, $textcolor = "0,0,0", $align = "horizontal")
{
$this->t = $text;
$this->h = $height;
$this->w = strlen($this->t) * $width;
$this->f = $fontsize;
$this->x = $x_axis;
$this->y = $y_axis;
$this->tc = explode("," ,$textcolor);
$this->a = $align;
}
function showimage()
{
$image_p = imagecreate($this->w, $this->h);
$background_color = imagecolorallocate ($image_p, 242, 242, 242); //transparent background
$text_color = imagecolorallocate ($image_p, $tc[0], $tc[1] , $tc[2]);
imagecolortransparent($image_p, $background_color );
if ($this->a == "vertical") { imagestringup($image_p, $this->f, $this->x, $this->y, $this->t, $text_color); }
else { imagestring ($image_p, $this->f, $this->x, $this->y, $this->t, $text_color); }
imagegif($image_p);
imagedestroy($image_p);
}
function toString()
{
$out = "<b>Text 2 Image Information </b><br />";
$out .="Text : " . $this->t . "<br />" .
"Height : " . $this->h . " px<br />" .
"Width : " . $this->w . " px<br />" .
"Font size : " . $this->f . "<br />" .
"X Axis : " . $this->x . "<br />" .
"Y Axis : " . $this->y . "<br />" .
"Text color: " . $this->tc[0] . " : " . $this->tc[1] . " : " . $this->tc[2] . "<br />" .
"Alignment : " . $this->a;
echo $out;
}
//Set functions
function setText ($value) { $this->t = $value; }
function setHeight ($value) { $this->h = $value; }
function setWidth ($value) { $this->w = $value; }
function setFontSize ($value) { $this->f = $value; }
function setX ($value) { $this->x = $value; }
function setY ($value) { $this->y = $value; }
function setFontColor ($value) { $this->fc = explode("," ,$value); }
function setAlign ($value) { $this->a = $value; }
//Get functions
function getText () { return $this->t; }
function getHeight () { return $this->h; }
function getWidth () { return $this->w; }
function getFontSize () { return $this->f; }
function getX () { return $this->x; }
function getY () { return $this->y; }
function getFontColor () { return $this->fc;}
function getAlign () { return $this->a; }
function headers()
{
header('Content-type: image/gif');
}
}