Use a wrapper script that reads an image from WMS and repaints it:
Wrapper
Here is an example written in PHP:
<?php $url = $_GET['url']; $im = imagecreatefrompng($url); if($im && imagefilter($im, IMG_FILTER_COLORIZE, 255, 0, 0, 0)){ // this line is only needed if original image has transparency (32bit/pixel) // and you want to preserve that transparency imagesavealpha($im, true); header('Content-type: image/png'); imagepng($im); }else{ echo 'Conversion failed.'; } imagedestroy($im); exit; ?>
Then, instead of calling your WMS link, you call the packer and pass the WMS link as a parameter (recolor_png.php? Url = ...). The shell reads the original image and returns a new PNG with a colorized version. Remember that the link you pass as a parameter must be correctly encoded (all special characters are replaced with their hexadecimal notation% XX). In JavaScript, you can do this using the encodeURIComponent () method.
Here is a working example of using your link and the above shell on my server:
http://www.digilog.de/pub/stackoverflow/recolor_png2.php?url=http%3A%2F%2Fgeoportal2.uhul.cz%2Fwms_oprl%2F%3FSERVICE%3DWMS%26REQUEST%3DGetMap%26SERVICEVERS%3ERSMS 3D1.1.1% 26LAYERS% 3DHMLCR% 26FORMAT% 3Dimage% 2Fpng% 3B% 2520mode% 3D24bit% 26FGCOLOR% 3D0xFF0000% 26TRANSPARENT% 3DTRUE% 26SRS% 3DEPSG% 3A4326% 26BBOX% 3D16.58935546875342% 348493% 299.3493% 468 3,449.38,463,849,384,634,634,672,634,634,672,634,634,634,634,634,634. 38237278700955% 26WIDTH% 3D256% 26HEIGHT% 3D256% 26STYLES% 3D
This is the resulting image (translucent version):
(source: digilog.de )
The same shell without translucent output (imagesavealpha removed from code):
http://www.digilog.de/pub/stackoverflow/recolor_png.php?url=http%3A%2F%2Fgeoportal2.uhul.cz%2Fwms_oprl%2F%3FSERVICE%3DWMS%26REQUEST%3DGetMap%26SERVICEVERS%3ERSMS 3D1.1.1% 26LAYERS% 3DHMLCR% 26FORMAT% 3Dimage% 2Fpng% 3B% 2520mode% 3D24bit% 26FGCOLOR% 3D0xFF0000% 26TRANSPARENT% 3DTRUE% 26SRS% 3DEPSG% 3A4326% 26BBOX% 3D16.58935546875342% 348493% 299.3493% 468 3,449.38,463,849,384,634,634,672,634,634,672,634,634,634,634,634,634. 38237278700955% 26WIDTH% 3D256% 26HEIGHT% 3D256% 26STYLES% 3D
And the resulting opaque image:
(source: digilog.de )
I will leave these wrappers online for a few days so you can check them out.
Caching
Since this conversion uses the processor heavily, it might be advisable to add some caching code to the shell:
- create a hash code from the given URL, for example: $ hash = md5 ($ url)
- check if image named $ hash.png exists in the storage subfolder
- if so: read the image from the file and return it
- otherwise: create an image, save it as $ hash.png in a subfolder and return it immediately
If you expect the contents of the WMS to change over time: also check the creation date of the cached images and delete them if they are too old (for example, a month or so). Thus, any changes to the WMS cards will be distributed to your system in a maximum of one month.