This is a discussion on Drawing and Calling an image? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I am just begining writing in PHP (5.2.0) after getting it installed and I am trying to get ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
"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 |
|
|||
|
"-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message news:YfGdnWdgOf6uHPPYnZ2dnUVZ_vmdnZ2d@comcast.com. .. > "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 > 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 |
|
|||
|
"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@comcast.com. .. >> "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 >> > > 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 |
|
|||
|
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... >> >> "-Lost" <spam_ninjaREMOVEME@REMOVEMEcomcast.net> wrote in message >> news:YfGdnWdgOf6uHPPYnZ2dnUVZ_vmdnZ2d@comcast.com. .. >>> "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 >>> >> >> 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 > |
![]() |
| Thread Tools | |
| Display Modes | |
|
|