For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > December 2006 > Drawing and Calling an image?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Drawing and Calling an image?
David

2006-11-29, 6:59 pm

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


-Lost

2006-11-30, 3:57 am

"David" <nobody@spamcop.net> wrote in message news:ekkna7$1jq8$1@news.iquest.net...
>I am just begining writing in PHP (5.2.0) after getting it installed and I


var $im = NULL;

'var' is deprecated in PHP 5.x. Use public/private/protected instead.

public $im = NULL;

....should fix your problem.

-Lost


David

2006-12-01, 6:57 pm


"-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message
news:YfGdnWdgOf6uHPPYnZ2dnUVZ_vmdnZ2d@co
mcast.com...
> "David" <nobody@spamcop.net> wrote in message
> news:ekkna7$1jq8$1@news.iquest.net...
>
> var $im = NULL;
>
> 'var' is deprecated in PHP 5.x. Use public/private/protected instead.
>
> public $im = NULL;
>
> ...should fix your problem.
>
> -Lost
>


Well I tried it... it did get better but not right still. It does now see
the size of the image, but still places an X in it, rather than putting in
the text.

David


-Lost

2006-12-01, 6:57 pm

"David" <nobody@spamcop.net> wrote in message news:ekps5e$2vu4$1@news.iquest.net...
>
> "-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message
> news:YfGdnWdgOf6uHPPYnZ2dnUVZ_vmdnZ2d@co
mcast.com...
>
> Well I tried it... it did get better but not right still. It does now see the size of
> the image, but still places an X in it, rather than putting in the text.
>
> David


*YOUR* code, *EXACTLY* as is runs just fine with *NO* error. All you have to do is change
that deprecated 'var' to 'public'.

I do not know what else to tell you aside from that.

-Lost


David

2006-12-04, 6:57 pm

Well it isn't you Lost ... it is me. I went back and copied the code I
posted here and it works. I still have the original files and they are what
I posted, line for line they are exactly the same. I checked the file size
of "img.php" and the old file is 1 byte more than the new file, so I have to
assume that it is some kind of control charater that I can't see (using
dreamweaver).

Thank you for your help Lost.

David


"-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message
news:I-ednTixStGdNO3YnZ2dnUVZ_smdnZ2d@comcast.com...
> "David" <nobody@spamcop.net> wrote in message
> news:ekps5e$2vu4$1@news.iquest.net...
>
> *YOUR* code, *EXACTLY* as is runs just fine with *NO* error. All you have
> to do is change that deprecated 'var' to 'public'.
>
> I do not know what else to tell you aside from that.
>
> -Lost
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com