View Single Post

  #1 (permalink)  
Old 11-29-2006
David
 
Posts: n/a
Default Drawing and Calling an image?

I am just begining writing in PHP (5.2.0) after getting it installed and I
am trying to get an image that is actually drawn in a different PHP file.
All I get is a small box with a red x in it...Anyway I am trying to keep
this broken down into very simple steps, so I can have a road map to follow
when I size up the code.

The file that does the drawing we will name "img.php" and it contains:
<?php
class img {
var $im = NULL;

function output_img () {

header ("Content-type: image/png"); //png header
$img_width = 100; $img_height = 100; //image size

//create image
$this->im = @imagecreatetruecolor($img_width, $img_height) or
die("Cannot Initialize new GD image stream");

//available image colors
$black = imagecolorallocate($this->im, 0, 0, 0);
$white = imagecolorallocate($this->im, 255, 255, 255);

imagefilledrectangle($this->im, 1, 1, $img_width - 2, $img_height - 2,
$white); // boarder

//draw array label times
imagettftext($this->im, 8, 0, 10, 10, $black, 'arial.ttf', 'test
text');

imagepng($this->im);
imagedestroy($this->im);

}
}
?>

The second file that is actually calling the above code we will name
"test_img.php" and it contains:
<?php
require('img.php');

$draw = new img();

$draw->output_img();
?>

If you remove the "class" from the first file and the "$this->" the image
will produce if you run the script... it just doesn't want to show using the
2 files. My feeling is I am doing something wrong with the "->" but it is
still rather a murky concept so I am splashing around and seeing if I can
clear it up.

David


Reply With Quote