Forum Moderators: coopster

Message Too Old, No Replies

imagegd2 doesn't work

         

yoavr

10:21 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



I tried this code: (which was taken from the php.net docs)
gd.php:
<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);

// Output the image
imagegd2($im);

// Free up memory
imagedestroy($im);
?>
but it didn't work. I got some weird characters instead.. (but not an error)

Matthew1980

10:40 pm on Feb 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Yoavr,

You need to tell the browser in the header that its an image if you are just getting characters echoed to the screen:-

imagegd2($im);

header("content-type: image/gif"); //if you know the filetype declare it here


then once you tell the browser that its an image, it should display what you expect. Give that a try and see how you get on...

Cheers,

MRb

yoavr

11:39 pm on Feb 1, 2010 (gmt 0)

10+ Year Member



Not working..
I can't set a header of "image/gif" because the this is not imagegif() function.
See [php.net...]

jatar_k

3:54 pm on Feb 2, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



the answer is correct though, you need to find the mime type for a GD2 image, I can't find one so the browser spits out garbage for me too

serve the proper content-type header and it will work

though from what I have quickly read it talks about using this compressed type for storage as it is much smaller and converting it to png or jpg

why the desire to spit out gd2 type images to the browser?

Matthew1980

4:32 pm on Feb 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there,

Yes I too have had a play with the code, and from what I can see the code spits out the right info, but because the header doesn't know whats coming it displays the raw data instead starting with the gd2 tag.

It does say that you need a GD2 compatible browser to view the file, but as yet I can't find a plugin (firefox). For now I will just use the 'standard' filetypes. But I will carry on playing with it until I can fathom it out...

MRb

rocknbil

8:57 pm on Feb 2, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does anyone even know if browsers support this image type? Maybe that's why it's so hard to find a mime type for it . . . it does say in the docs it's for devices that support GD2.

jatar_k

2:43 pm on Feb 4, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



from what i see it is unsupported, I think that line was written in such a way as to not write "nothing supports this so don't use it"