Fwd: Re: [MS4W-Users] transparency with php mapscript

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Fwd: Re: [MS4W-Users] transparency with php mapscript

Sven Schroeter
Hi all,

I'm fighting with the SWIG PHP MapScript Opacity again and found a very
strange behavior.

Here is my test script:

include("../includes/phpmapscriptng-swig/mapscript_70400.php");
$map = new mapObj(MAPFILE_PATH.'test.map');

// set image format
$map->selectOutputFormat("image/jpeg");
$oRasterLayer = $map->getLayerByName('tk_rlp_tms_grau');
$oPolyLayer = $map->getLayerByName('grenzen_vg');

$oRasterLayer->setOpacity(10);
$oRasterLayer->status = MS_ON;

$oPolyLayer->setOpacity(30);
$oPolyLayer->status = MS_ON;

// set image size
$map->setsize(1000,768);
$map->setextent(300497,5495624,366043,5558489);

// Bild im MapServer IMAGEPATH abspeichern.
$image = $map->draw();

//Bildname, Extension und Pfad
$picname = md5(rand());
$picext = ".jpeg";

$picpathname = MS_TMP_PATH.$picname.$picext;

// Bild im MapServer IMAGEPATH abspeichern.
$mapimage = $image->save($picpathname,$map); //URL


$imgurl = MS_TMP_URL.$picname.$picext;

//header('Location: '.$imgurl);

echo '<img src="'.$imgurl.'" border="1">';



If I set the width of the image to a number with 2 zeros at the end
everything works fine.
e.g. $map->setsize(800,814);
or $map->setsize(1000,768);

as soon as I change the value for the width of the image it often
doesn't work anymore and the layers don't have transparency anymore.
e.g. $map->setsize(801,814);
or $map->setsize(1011,768);

It is extremely difficult to see a pattern here.
All variants work with the old Mapscript.
Is this a bug?

Thanks + Greeting
Sven


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: transparency with php mapscript

jmckenna
Administrator
Hi Sven,

You found a good one.  It took me some time to figure out what is happening.

In fact this is due to MS4W 4.0.0 being compiled with Pixman support;
unfortunately I had hit this back in 2016 and removed Pixman for that
reason.  Here we are again though :)   I'll remove Pixman for the next
MS4W 4.0.1 release.  Follow along the progress at
https://ms4w.com/trac/ticket/218

Thanks for reporting this.

-jeff


--

Thank you for using MS4W.
"MS4W: open doors as well as windows"


--
Jeff McKenna
MapServer Consulting and Training Services
https://gatewaygeomatics.com/




On 2019-05-22 4:53 AM, Sven Schroeter wrote:

> Hi all,
>
> I'm fighting with the SWIG PHP MapScript Opacity again and found a very
> strange behavior.
>
> Here is my test script:
>
> include("../includes/phpmapscriptng-swig/mapscript_70400.php");
> $map = new mapObj(MAPFILE_PATH.'test.map');
>
> // set image format
> $map->selectOutputFormat("image/jpeg");
> $oRasterLayer = $map->getLayerByName('tk_rlp_tms_grau');
> $oPolyLayer = $map->getLayerByName('grenzen_vg');
>
> $oRasterLayer->setOpacity(10);
> $oRasterLayer->status = MS_ON;
>
> $oPolyLayer->setOpacity(30);
> $oPolyLayer->status = MS_ON;
>
> // set image size
> $map->setsize(1000,768);
> $map->setextent(300497,5495624,366043,5558489);
>
> // Bild im MapServer IMAGEPATH abspeichern.
> $image = $map->draw();
>
> //Bildname, Extension und Pfad
> $picname = md5(rand());
> $picext = ".jpeg";
>
> $picpathname = MS_TMP_PATH.$picname.$picext;
>
> // Bild im MapServer IMAGEPATH abspeichern.
> $mapimage = $image->save($picpathname,$map); //URL
>
>
> $imgurl = MS_TMP_URL.$picname.$picext;
>
> //header('Location: '.$imgurl);
>
> echo '<img src="'.$imgurl.'" border="1">';
>
>
>
> If I set the width of the image to a number with 2 zeros at the end
> everything works fine.
> e.g. $map->setsize(800,814);
> or $map->setsize(1000,768);
>
> as soon as I change the value for the width of the image it often
> doesn't work anymore and the layers don't have transparency anymore.
> e.g. $map->setsize(801,814);
> or $map->setsize(1011,768);
>
> It is extremely difficult to see a pattern here.
> All variants work with the old Mapscript.
> Is this a bug?
>
> Thanks + Greeting
> Sven
>
>
_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: [MS4W-Users] transparency with php mapscript

Gramenz, Jens
In reply to this post by Sven Schroeter

Hi Sven,

I encountered the same problem few weeks ago. The pattern does exist: If the width of the image is not evenly divisible by four, than the layer transparency fails.

I was just about to write a message like yours, but as I managed to reproduce the bug with a small testscript, I stumbled upon an error and then found out that it is already a known thing…

 

http://osgeo-org.1560.x6.nabble.com/Layer-opacity-not-working-td5292269.html

 

As Jeff pointed out, if you built it on your own, then you can disable pixman, if you don’t actually need it… Cairo support was dependent of pixman I think.

If you are using a compiled package, maybe you can circumvent this issue by using the OPACITY at CLASS level. I know that OPACITY is already deprecated, but it might be useful until we are forced to use COMPOSITE blocks.

 

LAYER

__OPACITY 50 # doesn’t work

__CLASS

____STYLE

______OPACITY 50 # works

____END

__END

END

 

If the layer objects are disjoint, the result should be the same. If polygons of the same layer overlap their opacities will add up, which or might not be useful behaviour…

 

I am also interested in alternatives. For example: Is it possible to change pixman, so the bug doesn’t occur? Sadly, I didn’t manage to compile Mapserver with PHP7 myself yet. If it turns out that nobody needs Pixman/Cairo and MS4W will be compiled without it, it would be fine for me as well.

 

Best wishes,

Jens

 


_______________________________________________
mapserver-users mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/mapserver-users