imagecreate inside an object
| From: | Lorenzo Marussi | Date: | Thu, 19 Aug 2010 22:44:36 +0000 |
| Subject: | imagecreate inside an object | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-307588@lists.php.net to get a copy of this message | ||
hello list,
I'm trying to manage a image resouce inside a method, but
unsuccessfully...
In detail, that's some code snippets:
the class and the method:
class.php
class canvas{
function makeImage($imageWidth = 850){
$im = imagecreate(110, 20) or die("Cannot Initialize new GD
image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
return $im;
}
}
... than my test.php file:
header("Content-type: image/png");
include_once("class.php");
$c = new canvas();
imagepng($c->makeImage());
the result in the browser isn't the image itself, but an error that
sounds like: (I traslate the message from italian):
"Image can't be displayed because contains some errors"
but... if I comment out the "header" line, I get this:
‰PNG ���
IHDR���n������V,š���PLTE���é[an÷���fIDAT•c
fxÄÀÃ`Ç
ÀçÀä²41ƒ‚€˜Ë–Ý’Àq²@੤;{á0— œi
...sounds like a png image, isn't it? but It doesn't :-/
The code in the method is very simple, is the same of the php manual
page of "imagecreate" function, and I think the resource is correctly
managed, 'cause if I write this:
$c = new palinsestoCanvas(3);
imagepng(null);
I get: "Warning: imagepng(): supplied argument is not a valid Image
resource"
.. so I think $c->makeImage()) returns successfully the resource.. but I
still didnt see my image..
Any help is appreciated, thanks
Lorenzo