|
Posted by Richard Lynch on 10/04/68 11:08
Aaron Todd wrote:
> I just wrote a little script to play around with the GD library but I am
> having a problem displaying it in the browser. I have not problem at all
> when I just run the script. But I was trying to make the image in a
> custom
> function which will return the image when its called. All I end up
> getting
> is a bunch of weird characters.
Those weird characters ARE the image.
Most likely, you finally got it right, and got rid of all the error
messages, and now your image is PERFECT.
However, when you have the errors in it, PHP sent out a "Cotnent-type:
text/html" header before the error messages -- so you could see them as
text error messages, which they were.
At that time, Internet Explorer *CACHED* those headers, and is now
thoroughly convinced that the URL *is* text/html, even though you are no
longer sending that header. So IE is going to keep showing you the
document as text/html, because IE is really stupid.
If you quit IE, and start up again, and surf to the image, it should all
just work.
Oh, and don't do:
echo ImagePNG($im);
Just to:
ImagePNG($im);
The imageXYZ functions print out the image already, and then return 0 or
-1 or something based on their success/failure to print the image.
The way it works out, you're actually dumping out the image and then some
bogus data at the end -- because the ImagePNG gets called FIRST, which
prints out the image, and then your echo prints out the return value after
all the image data went out.
Most browsers probably gonna ignore that bogus extra data at the end of
the image.
You might want to add some error checking to your code.
And use imagecreatetruecolor() to make a cleaner pie internally, even
though you are converting to PNG in the end.
> Here's my code:
> function makepie($slice, $total){
> $height = 150;
> $width = 150;
> $im = ImageCreate($width, $height);
> $bck = ImageColorAllocate($im, 255,255,255);
> $black = ImageColorAllocate($im, 0, 0, 0);
> $red = ImageColorAllocate($im, 255, 0, 0);
> imagefilledellipse($im, 75, 75, 125, 125, $red);
> imageellipse($im, 75, 75, 125, 125, $black);
>
> //Making the Slice
> $pieslice = (($slice / $total) * 360) + 315;
> imagefilledarc($im, 75, 75, 125, 125, 315, $pieslice, $black,
> IMG_ARC_PIE);
>
> //Return
> header("Content-type: image/png");
> echo ImagePNG($im);
> }
>
> Anyone have any idea why I cant return the image?
>
> Thanks
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Like Music?
http://l-i-e.com/artists.htm
Navigation:
[Reply to this message]
|