[mapguide-internals] changing mapguide's image type

Paul Spencer pspencer at dmsolutions.ca
Mon Feb 5 13:40:11 EST 2007


Trevor, I have some experience with the png thing :)  There is no  
problem overlaying 8 bit png with transparency in any browser.  The  
problem starts in IE when you use PNG24 with alpha transparency.   
PNG24 with normal transparency works.  Its only the alpha  
transparency that breaks things.

The defacto standard for working around this is to use something  
called the pngHack.  pngHack works by changing the source of the  
image to a transparent image (gif or png, it doesn't matter) and  
creating a css style filter that uses the AlphaImageLoader to load  
the png24.

The smallest, most workable hack I have been able to create for this  
is the one I use in ka-Map, Fusion and other projects.  There are two  
components, a CSS style and a javascript function.  The hack is  
applied by adding the class png24 to an image.  The only requirement  
is that the image must have a size.  Also, if you want to change the  
source of the image after it is created, you have to actually change  
the filter, not the src of the image.

The css style is:

/* img elements with a class of png24 will have the png24 filter hack  
applied
  * in IE browsers only.  To make this work, images MUST have a width  
and height
  * specified.  The minimum tag required is:
  *
  *     <img class="png24" src="<url>" width="xx" height="xx">
  */
img.png24 { filter:expression(applyPNGFilter(this)) }

The javascript function is:

/*
  *  applyPNGFilter(o)
  *
  *  Applies the PNG Filter Hack for IE browsers when showing 24bit  
PNG's
  *
  *  var o = object (this png element in the page)
  *
  * The filter is applied using a nifty feature of IE that allows  
javascript to
  * be executed as part of a CSS style rule - this ensures that the  
hack only
  * gets applied on IE browsers :)
  */
function applyPNGFilter(o) {
     var t="images/a_pixel.png";
     if( o.src != t ) {
         var s=o.src;
         o.src = t;
         o.runtimeStyle.filter =  
"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+s 
+"',sizingMethod='scale')";
     }
}

Oh, I guess there is one other requirement :)  You need images/ 
a_pixel.png to be a 1x1 transparent 8bit png (or you could substitute  
a gif if you prefer).

This also works for dynamically created images:

var img = document.createElement('img');
img.src = 'a-png24-image.png';
img.width = 256;
img.height = 256;
img.className = 'png24';

something.appendChild(img);

Cheers

Paul

On 5-Feb-07, at 1:21 PM, Trevor Wekel wrote:

>
> Yes.  I think so.  The tiles and the overlay are two separate HTTP
> requests.  Tiles could be JPG and overlay could be PNG.  If you're  
> using
> tiles, then the overlay should be PNG so transparency can be used to
> show the tiles underneath.
>
> I'm not sure this has been tested though.  It would be interesting to
> see if the various browsers can deal with overlaying a transparent PNG
> image over a non-transparent JPG.
>
> And I agree that image type and image size should ideally be set per
> base layer group.  However, that's a fair bit more work to implement
> (map definition, Web Studio, Studio, viewers) than adding  
> configuration
> parameters for default behaviours.
>
> Thanks,
> Trevor
>
> -----Original Message-----
> From: mapguide-internals-bounces at lists.osgeo.org
> [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of Paul
> Spencer (External)
> Sent: Monday, February 05, 2007 10:57 AM
> To: MapGuide Internals Mail List
> Subject: Re: [mapguide-internals] changing mapguide's image type
>
> Ideally the image type would be set per base layer group.
>
> Paul
>
> On 5-Feb-07, at 12:43 PM, Jason Birch wrote:
>
>>
>> So, if the tiling service image type could be specified, would that
>> allow Paul to use JPG for the tiles, and the interface would still  
>> use
>
>> PNG for the overlays?
>>
>> Jason
>>
>> -----Original Message-----
>> From: mapguide-internals-bounces at lists.osgeo.org
>> [mailto:mapguide-internals-bounces at lists.osgeo.org] On Behalf Of
>> Trevor Wekel
>> Sent: Monday, February 05, 2007 09:40
>> To: MapGuide Internals Mail List
>> Subject: RE: [mapguide-internals] changing mapguide's image type
>>
>>
>> Yes.  Andy is right.  If you're not using tiles then the image type
>> can be specified.  However, tile generation is currently hardcoded as
>> PNG.
>>
>> Thanks,
>> Trevor
>> _______________________________________________
>> mapguide-internals mailing list
>> mapguide-internals at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>
> +-----------------------------------------------------------------+
> |Paul Spencer                          pspencer at dmsolutions.ca    |
> +-----------------------------------------------------------------+
> |Chief Technology Officer                                         |
> |DM Solutions Group Inc                http://www.dmsolutions.ca/ |
> +-----------------------------------------------------------------+
>
>
>
>
> _______________________________________________
> mapguide-internals mailing list
> mapguide-internals at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-internals
>
> _______________________________________________
> mapguide-internals mailing list
> mapguide-internals at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-internals

+-----------------------------------------------------------------+
|Paul Spencer                          pspencer at dmsolutions.ca    |
+-----------------------------------------------------------------+
|Chief Technology Officer                                         |
|DM Solutions Group Inc                http://www.dmsolutions.ca/ |
+-----------------------------------------------------------------+






More information about the mapguide-internals mailing list