membender has asked for the wisdom of the Perl Monks concerning the following question:
Hello, I'm trying to return an image in a cgi script and the code works for jpgs, but not for pngs. Here's the code that works for jpgs:
use strict; print "Content-type: image/jpg\n\n"; my $file_name = "./images/picture.jpg"; binmode IMAGE; binmode STDOUT; open IMAGE, $file_name or die "ERROR $!"; while(read IMAGE, $buff, 1024) { print STDOUT $buff; } close IMAGE; 1;
This returns the image just as I hoped and expected. However, if I merely change the two occurrences of 'jpg' above to 'png', it returns nothing! Both picture.jpg and picture.png exist of course, in the proper place.
I've tried all combinations of with and w/o binmode, a full path to the file, buffering to a temporary variable before printing, etc. and always get the same result. Tested on IE and Chrome.
Any help is greatly appreciated. I've got a fair amount invested in keeping the images as pngs. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Returning jpg works, png NOT
by Corion (Patriarch) on Jul 06, 2011 at 08:23 UTC | |
by ambrus (Abbot) on Jul 06, 2011 at 09:13 UTC | |
by membender (Novice) on Jul 06, 2011 at 18:49 UTC | |
|
Re: Returning jpg works, png NOT
by davido (Cardinal) on Jul 06, 2011 at 07:47 UTC | |
|
Re: Returning jpg works, png NOT
by i5513 (Pilgrim) on Jul 06, 2011 at 08:01 UTC | |
|
Re: Returning jpg works, png NOT
by moritz (Cardinal) on Jul 06, 2011 at 07:48 UTC |