Re: imagecreate inside an object

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2010-08-20 at 00:44 +0200, Lorenzo Marussi wrote:

> 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
> 
> 
> 
> 


It looks like you might be outputting some extra content to the browser,
such as newlines or other content. Use the second parameter of
imagepng() to write the image to a file and compare the size of that
with the bytes sent to the browser (you should be able to get this from
the browsers properties dialogue)

>From the looks of what you've pasted, the extra content is appearing
right after the image data, so perhaps an exit; call right after
imagepng() and seeing if that solves the problem.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux