[mapserver-users] mapserver vs mapscript: agg + transparency + quantize not working

Roger André randre at gmail.com
Thu Nov 5 10:55:38 PST 2009


Hi Tiemens,

Not sure if this helps, but in some of the testing I did with Python
mapscript, I specified the following in my code:

map.selectOutputFormat("AGGPNG24")

That seemed to do the trick for me.  The script is inline below, in case it
might help give context.

Roger
--
#! /usr/bin/python

# mimic the Mapnik 'hello world' at
# http://trac.mapnik.org/wiki/GettingStarted
# based on example in Web Mapping Illustrated

import mapscript

# create a base mapfile
map = mapscript.mapObj()
map.selectOutputFormat("AGGPNG24")
map.name = "CustomMap"
map.setSize(1000, 500)
#map.setExtent(-180.0, -90.0, 180.0, 90.0)
map.setExtent(-22, -36, 60, 38)
map.imagecolor.setRGB(70,130,180)
map.units = mapscript.MS_DD

# set Web image params
map.web.imagepath = "/var/www/tmp/"
map.web.imageurl = "/tmp"

# create layer object
layer = mapscript.layerObj(map)
layer.name = "countries"
#layer.type = mapscript.MS_LAYER_LINE
layer.type = mapscript.MS_LAYER_POLYGON
layer.status = mapscript.MS_DEFAULT
layer.data = "/home/randre/gis_data/unep/unep_coastlines.shp"
layer.template = "template.html"

# create a class
class1 = mapscript.classObj(layer)
class1.name = "Countries"

# create a style
style = mapscript.styleObj(class1)
style.outlinecolor.setRGB(125,125,125)
style.width = 1
style.color.setRGB(240,240,240)
#style.antialias = mapscript.MS_TRUE

# write the map object into a map file
#map.save("custom.map")

# write out an image using these params
mapimage = map.draw()
mapimage.save("ms_world.png")
--
On Thu, Nov 5, 2009 at 9:04 AM, Tiemens, Gerben
<Gerben.Tiemens at grontmij.nl>wrote:

>   I am busy writing a application with mapscript in C#.
>
> Currently I am facing the earlier mentioned problems of agg + transparent
> images + quantization.
>
> Is the new MS4W compiled with the quantization options?
>
> The image background is now Black. The labels are dissapearing.
>
> It should be an image wich is completly transparent with some colored lines
> and some black labels.
>
> Setting the imagecolor will not help me.
>
> Images without quantization options on, are perfect and beautiful png's.
>
>
>
> What I am using now is this:
>
> MS4W 3.0 Beta 7   which contains Mapserver 5.4.2
>
>
>
> C# mapscript
>
>
>
> Mapfile is completely written in C#, so all default options apply.
>
> I saved this mapfile from my mapobj
>
>
>
> ----------------------
>
> MAP
>
> EXTENT 104952 495303 105452 495803
>
> IMAGECOLOR 255 255 255
>
> IMAGETYPE gif
>
> SIZE 2000 2000
>
> STATUS ON
>
> UNITS METERS
>
> NAME "MS"
>
> OUTPUTFORMAT
>
> NAME "PNG_mapscript"
>
> MIMETYPE "image/png; mode=24bit"
>
> DRIVER "AGG/PNG"
>
> EXTENSION "PNG"
>
> IMAGEMODE "RGBA"
>
> TRANSPARENT TRUE
>
> FORMATOPTION "QUANTIZE_FORCE=on"
>
> FORMATOPTION "QUANTIZE_DITHER=off"
>
> FORMATOPTION "QUANTIZE_COLORS=256"
>
> END
>
> SYMBOL
>
> NAME "circle"
>
> TYPE ELLIPSE
>
> FILLED TRUE
>
> POINTS
>
> 1 1
>
> END
>
> END
>
> --
>
> *snip*
>
> --
>
> END
>
>
>
> ----------------------------------------
>
>
>
> In addition to above: further testing revealed that the transparent color
> is always black.
>
>
>
> So if I set
>
> imagecolor 99 99 99
>
> transparent = true
>
> And outputformat to:
>
> OUTPUTFORMAT
>
> NAME "PNG_mapscript"
>
> MIMETYPE "image/png"
>
> DRIVER "GD/PNG"
>
> EXTENSION "PNG"
>
> IMAGEMODE "RGBA"
>
> TRANSPARENT TRUE
>
> FORMATOPTION "QUANTIZE_FORCE=on"
>
> FORMATOPTION "QUANTIZE_COLORS=256"
>
> FORMATOPTION "QUANTIZE_NEW=on"
>
> END
>
> The image appears grey.
>
> The black labels with white backgroundcolor and black shadowcolor in
> original image are mapped to: white background with gray outline characters
> and transparent filling and the shadow is grayoutlined with transparent
> filling. Probably the antialiasing generates the grey outline, the black
> filling is converted to transparent.
>
> Something is going wrong.
>
>
>
> If I set output format to:
>
> OUTPUTFORMAT
>
> NAME "PNG_mapscript"
>
> MIMETYPE "image/png; mode=24bit"
>
> DRIVER "AGG/PNG"
>
> EXTENSION "PNG"
>
> IMAGEMODE "RGBA"
>
> TRANSPARENT TRUE
>
> FORMATOPTION "QUANTIZE_FORCE=on"
>
> FORMATOPTION "QUANTIZE_DITHER=off"
>
> FORMATOPTION "QUANTIZE_COLORS=256"
>
> END
>
> The same applies for the text/labels, but background of the image is now
> black in all circumstances (no matter what color of imagecolor setting.
>
>
>
> ---------------------------------------------------
>
>
>
> Further research drills down to where the problem may occur:
>
> If i test my saved mapfile from mapscript into the
> apache/cgi-bin/mapserv.exe
>
> The image is coming out as it should be.
>
> Transparent background, features like it should be, and text also as it
> should be.,  but if I use the draw() method from mapscript, it comes out
> crippled.
>
>
>
>
>
> Am i doing something wrong in mapscript? Are there configurations that I
> may miss in mapscript that are default in mapserv.exe?
>
> I also do'nt know if this is a problem of Mapserver or MS4W, therefore
> crossposting it.
>
> Greetings
>
>
> Gerben
>
>
> << Please read our E-mail Disclaimer at: Emaildisclaimer.Grontmij.com >>
>
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20091105/a1e9f5b0/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ms_test.py
Type: application/x-python
Size: 1223 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20091105/a1e9f5b0/attachment.bin>


More information about the MapServer-users mailing list