[Mapserver-users] perl/mapscript: gd pointer to imageObj ?

Sean Gillies sgillies at frii.com
Fri May 21 10:31:20 EDT 2004


On May 21, 2004, at 1:31 AM, Manfred Meier wrote:

> Hello list,
> i would like to modify an image created in mapscript, for example to 
> add a logo or a chart diagram. For this i could use GD (having some 
> knowledge how to do). So, can I get an GD-Pointer from the imageObj?
> Like for example:
>
> $img = $map->prepareImage();
> $layer->draw ($map, $img);
> ....
> $map->drawLabelCache($img),
> ....
> $gdptr = $img->gd;	#  ??? like that
> ....
>
> Thanks
> Manfred
>
>

Manfred,

No.  The gd member of the MapServer imageObj structure is not currently
exposed to mapscript, so the imageObj class has no gd attribute.  We
could expose the gd pointer by making a few small changes, but it would
not be something you could easily use.  It would be a SWIG pointer, not
an object that you could manipulate with a Perl GD module.

I have written a couple extra methods for the Python mapscript module
which let us save images to a string in memory, and read imagery from
Python file-like objects.  This allows us to do

     ms_image = test_map.draw()    # Draw a GD PNG image

     # Store in memory using Python's file-like StringIO class
     mem_png = StringIO.StringIO(ms_img.saveToString())

     # Open as a Python Imaging Libray Image and manipulate
     image = PIL.Image(mem_png)
     ...

     # Return manipulated imagery to an imageObj instance for
     # further map drawing
     processed_mem_png = image.save(StringIO.StringIO())
     processed_ms_image = mapscript.imageObj(0, 0, 'GD/PNG', 
processed_mem_png)

without ever writing any imagery to the filesystem.  See

     http://users.frii.com/sgillies/projects/mapscript/4.2/python.html 
for

more examples.

At the MapServer Users Meeting in June I am doing a workshop on SWIG 
mapscript,
including Perl, and intend to talk about this and recommend some ways 
that
Perl users may implement similiar methods using a filehandle opened to 
imagery
as a scalar instead of Python's StringIO.

cheers,
Sean




--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies





More information about the mapserver-users mailing list