Jul 22

Getting Around IE's PNG Issues

PNG is an awesome image format, primarily useful for its ability to support 8-bit transparency (that is, an alpha channel where there’s a continuum from opaque to transparent, instead of the simple on/off transparency of GIF). So what’s been holding you back from using it? IE for Windows, mostly, which is the only browser left that doesn’t support the PNG alpha channel properly.

When IE 5.5 rolled around, IE gained some ability with PNG’s in the form of the AlphaImageLoader filter. In the past, I’ve gotten around the IE problem by using this filter, but you really have to kludge up your HTML to implement it.

Bob Osola has a solution that’s downright diabolical.

The code can be used either by a one-time copy-and-paste or as an include file. The entire thing is completely ignored by all other browsers - in fact it is treated as an HTML comment - thanks to IE’s conditional comments. This solution is therefore light, portable and non-invasive to other browsers.

I wish there wasn’t a need for a hack like this, but it appears that MS has stopped further development of IE. So the choice as of June 2004 is: ignore PNGs or use hacks.

He hides the script block in a conditional comment, one of the few helpful features of IE (although I only use it to fix problems with IE, I guess ‘helpful’ is a bit too generous).

The script spools through all the images on the page, finds all the ones whose source ends in ‘.png’, and changes them to spans that have the image as the background, filtered through AlphaImageLoader. So you don’t need to add any special code to your PNG IMG tags in order to use it.

It should work on all non-IE browsers (since it does nothing), and all versions of IE older than 5.5. That maps to enough of the browser market to suit my tastes. The site also lists a couple of alternative ways around the problem. Well done.


Comments

by Rich,   July 22, 2004 6:00 PM  

That is so cool. I just applied this to some of the sites I work on... thx for the pointer.


by Matt,   July 22, 2004 6:29 PM  

Oh man, I just had that problem a few weeks back and was pulling my hair out! Thanks for the link Joe! Yer my boy, blue!


by Jeroen,   July 23, 2004 10:09 AM  

The IE7 script (http://dean.edwards.name/IE7/) also adds PNG transparency to IE browsers.


by sean hogge,   May 9, 2005 1:13 AM  

I've recently used the same script via include for a web site I'm developing in which .PNGs are a must. I've also found that apparently you cannot use JavaScript to alter the src attribute of a PNG.

After trying to target them even by number instead of names (document.images[0]) it appears that IE "skips" .PNGs in the document.image collection enumeration?

Anyone else encountered this issue or found a way around it? I'm looking about, and if I find it, I'll post it here barring someone beating me to it.


by Dan,   December 4, 2007 1:46 PM  

Question. We are fixing any IE6 problems (transparency, etc), but now I have come across a real twisted one.

I have three png's in a row. One of the png's insists on shrinking width-wise. I have given it a table, I have changed the file type, I have done everything I could think of, but I am stumped! Heeelp. If anyone has an answer, could you please email me at dan.bringhurst@omnibizsolutions.com? Thanks you guys!



Add Comment


Want to advertise on this site? Contact FM.
Laser Toner Cartridges UK laser toner, toner cartridges, hp toner, lexmark toner, samsung toner, canon, toner, epson toner, oki toner, kyocera toner, xerox toner, remanufactured toner, compatible toner
Direct TV Deals Free 4 room direct tv deals. no equipment to buy. free fast professional direct tv installation. this is the best direct tv deal available anywhere.
SEO Article Learn from the experts with our SEO article.
rope light Shopping with birddog distributing, inc., gives you access to the lowest prices, the best customer service and the quickest delivery times possible.
Laptop AC Adapter We offer genuine factory direct replacement AC adapters.
Direct TV Best satellite TV deals.
Direct TV Deals Direct TV programming deals are varied and include packages containing from 50 channels up to over 250 channels.
8mm film to DVD Retain family memories with the only frame by frame digital restoration service in the United States for your 8mm film to DVD today
Rubber Stamp Shop for custom self-inking stamps, hand stamps, address stamps, label stamps, check endorsement stamps, check deposit stamps, date stamps, pre inks, pocket stamps, ink and much more!