[Mapserver-users] Sending image to stdout under Apache

Dana Quinn dana at nextbus.com
Wed Mar 5 11:54:32 EST 2003


(sorry if this hits the list twice)

Hi-
	I'm sorry, I should have written about what solved the problem
I had back then.  (in the thread that Eric referenced).  My problem
looked like it was happening because the image data was coming
before the header data.  So, I was concerned that some sort of
output buffering was at fault.  Acting on a tip I read somewhere,
I added this at the top of my script:

use FileHandle;
STDOUT->autoflush;

I don't know if this sort of thing is usually necessary when using
CGI.pm, but things work great now.

and now my sequence for outputting to the browser goes like this:

print "Content-Type: image/png\r\n\r\n";
$img->saveImage(undef, $mapscript::MS_PNG, $map->{transparent},
	$map->{interlace}, 0);

and it works fine.

Now that I think about it, it would probably be better to use
the CGI method:
print $query->header('image/png'); instead of the 'print
"Content-Type... stuff I have there now.

dana


Eric Bridger wrote:
> 
> The list archives show that this came up last Dec.
> (http://mapserver.gis.umn.edu/data2/wilma/mapserver-users/0212/msg00265.html) and while a work around was suggested there was no solution to the problem given, so I was wondering if anyone else had run into this problem. 
> 
> I'm having a problem using Perl mapscript $img->saveImage(undef, ...),
> to send an image, PNG and/or JPEG, to the standard output under Apache. 
> Running in /cgi-bin I have the following script: 
> 
> my $map = new mapscript::mapObj($ms_dir . "/test.map"); 
> 
> my $ref_img = $map->drawReferenceMap(); 
> 
> # This works fine: 
> #$ref_img->saveImage("junk.png", $mapscript::MS_PNG,  
> $map->{transparent}, $map->{interlace}, 0); 
> 
> print "HTTP/1.0 200 OK\n"; 
> print "Content-type: image/png\r\n\r\n"; 
> binmode STDOUT; 
> 
> # this produces no output on Apache's STDOUT 
> $ref_img->saveImage("", $mapscript::MS_PNG, $map->{transparent},
> $map->{interlace}, 0); 
> 
> $ref_img->free(); 
> exit; 
> 
> 
>>From the command line this script works as expected.  But when run under
> Apache/mod_perl  it's as if the C msSaveImage() stdout stream is
> pointing somewhere other than the Apache stdout (i.e. the client
> browser). 
> 
> The work around of course is to save a disk file and then print it, but
> the whole point of this is to avoid the temp. disk files.  I've noticed
> a significant increase in performance when using mapserv as an image
> engine rather then using temp disk files. 
> 
> Thanks. 
> Eric 
> 
> 
> Setup: 
> 
> Apache/1.3.26 (Unix) 
> Mapserv 3.6.4 
> mod_perl 1.22 
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users






More information about the mapserver-users mailing list