Jump to content


Photo

Slight problem with GD and PNG file support


  • Please log in to reply
6 replies to this topic

#1 magnav0x

magnav0x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 12:41 AM

I have an issues when generating PNGs. The actual images come up just fine...no problem there, but if I right click on the generated image and try to save it, it only gives me the option of saving it as a .bmp in IE. In Firefox, it won't even allow me to download the image....well I can, but it won't be a valid image. Also, in IE when I right click on the generated images it says "Not Available" next to the File Type descriptor. Is this a common problem or something I may be doing? I basically want the users to be able to right click on the generated image and actually save it as a PNG image.

I'm using:
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);

Thanks in advance guys!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 18 April 2006 - 12:48 AM

This should be OK... But where is the image resource ($im)?

Also note that your script actually outputs an image, meaning that you shouldn't mix it with HTML or whatever, like.
~ D Kuang

#3 magnav0x

magnav0x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 12:55 AM

[!--quoteo(post=365788:date=Apr 17 2006, 07:48 PM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 17 2006, 07:48 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This should be OK... But where is the image resource ($im)?

Also note that your script actually outputs an image, meaning that you shouldn't mix it with HTML or whatever, like.
[/quote]

Using a standard
$im = imagecreatefrompng("whatever.png");

No HTML is used on the page that is displaying the generated image at the moment. The only thing displayed on the page is generated by imagepng()


#4 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 18 April 2006 - 01:19 AM

have you tried imagejpeg or imagegif to see if ie and firefox just don't like PNG?

Also, how is the file referenced? is it <img src="image.jpg"> or <img src="image.php?id=234"> or the like? You might have to cloak your php with something like .htaccess

#5 magnav0x

magnav0x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 02:45 AM

[!--quoteo(post=365804:date=Apr 17 2006, 08:19 PM:name=michaellunsford)--][div class=\'quotetop\']QUOTE(michaellunsford @ Apr 17 2006, 08:19 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
have you tried imagejpeg or imagegif to see if ie and firefox just don't like PNG?

Also, how is the file referenced? is it <img src="image.jpg"> or <img src="image.php?id=234"> or the like? You might have to cloak your php with something like .htaccess
[/quote]

I haven't tryed using the gif or jpg functions, because the script I wrote, relies on the outputed file to be PNG (8bit). I may mess with them tomorrow though out of curiosity, just to see if IE and FF throw fits with them as well. I already had a .htaccess file setup for the PNG script and I'm not calling the image via HTML at all.

[a href=\"http://www.somewhere.com/image.png\" target=\"_blank\"]http://www.somewhere.com/image.png[/a] (which would execite...image.php as defined by the .htaccess file)

When the script is run it does it's thing and generates the PNG image to the screen, that's it. No overhead at all on it.

#6 magnav0x

magnav0x
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 April 2006 - 04:34 PM

Ok, I pretty much think I figured out what exactly is causing the problem. In short the script is suppose to let the user upload a JPG and the script then does some "modifying" on the image and regenerates it as a PNG (must be 8bit).

Scenario 1:
I uploaded a JPG image to the same directory as the script and just hard coded that images name into the script. When it generates the PNG everything is fine and dandy, I can save the image as PNG in IE and FF.

Scenario 2:
Use HTML form that allows the user to upload an image. The form calls the said PHP script and uses the file that they uploaded in the script, but can not save as a PNG in IE or FF.

All morning I've been trying different things and it seems that as long as the PHP script is being referenced by a HTML form, it will NOT work. Can anyone think of a work around for this? I've tryed making the HTML form submit to a stand alone PHP script that would upload the file and store the name of the file in a session and then use HEADER to redirect to the actual generation script and then use the session variable of the file name, but that is a no go as well.

#7 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 18 April 2006 - 07:33 PM

Re saving images using IE -

I've never been able to save any type of image (png, gif, jpg) in a format other than bmp using IE.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users