homepage Welcome to WebmasterWorld Guest from 54.243.13.30
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
How to display more than one image
ac1982




msg:3587002
 12:42 pm on Feb 28, 2008 (gmt 0)

Hi, i have created the following class and is working fine for a single image, but I would like to instantiate this as many times as I want inside a page to generate different images and when I tried only the first image shown. Thank you

$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');
}

}

 

coopster




msg:3588462
 11:55 pm on Feb 29, 2008 (gmt 0)

You have an undefined variable on line 30 ($tc should be $this->tc). Also, if you want to show more than one image on the page, create another page that has <img> elements in it that call upon this class to build the images for each "src" attribute.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved