[MS4W-Users] ms_iogetstdoutbufferstring() returns "empty image"

andrew_peru rummagebin at gmail.com
Fri Mar 18 14:34:53 EST 2011


I'm using php mapscript with ms4w v. 3.0.1, which I guess translates to
Mapserver cgi 5.6.6 and Mapscript 5.6.6

I need to load the image produced by a Mapserver WMS into a php variable in
order to perform some on-the-fly image processing before serving it up to a
browser.  

The following php code snippet works but is inefficient because it loads an
image into two different buffers, one of which is never used  (This,
however, was the only way I got the concept to work at all)
.
.
$objMap = ms_newMapobj($map_path.$map_name);
ms_ioinstallstdouttobuffer();              # make output go into mapserver
buffer
$objMap->owsdispatch($request);    # This would print to browser, but goes
to mapserver buffer
ms_ioresethandlers();

ob_start();                                          # make output go into
php buffer
$image = $objMap->draw();               # Instance of Image object
$image->saveImage('',$objMap);       # This would print to browser but goes
to php buffer
$buffer = ob_get_contents();             # Php Buffer (image) contents
placed into variable/memory
ob_end_clean();                                 # Output buffer cleaned so
image not printed automatically

header('Content-type: image/png');
echo $buffer;                                      # Image is displayed
successfully in browser
.
.
.

On the other hand this code snippet attempts to bypass the whole the
ob_start() to ob_end_clean() hack, but it fails:
.
.
$objMap = ms_newMapobj($map_path.$map_name);
ms_ioinstallstdouttobuffer();              # make output go into mapserver
buffer
$objMap->owsdispatch($request);    # This would print to browser, but goes
to mapserver buffer
$buffer = ms_iogetstdoutbufferstring();   # This should load mapserver
buffer to php variable
ms_ioresethandlers();

header('Content-type: image/png');
echo $buffer;                                           # Fails with error
message
.
.
Here browser spits out the following error message : 
The image "" cannot be displayed, because it contains errors.

If I comment the header function I can see that ms_iogetstdoutbufferstring()
is returning a stream consisting of the characters "PNG" surrounded by one
or two bytes of binary stuff, nothing else.

Has anybody seen this behavior before?  Should I get a new copy? Modify some
setting?
Any help will be greatly appreciated.


--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/ms-iogetstdoutbufferstring-returns-empty-image-tp6185879p6185879.html
Sent from the ms4w-users mailing list archive at Nabble.com.


More information about the MS4W-Users mailing list