Fixing PNG transparency display problem with IE6
By Fili • Feb 22nd, 2007 • Category: Web DevelopmentOne of the most annoying bugs in IE6 that I keep running into is lack of support for a PNG file that isn’t PNG8. In order to for a PNG24 to display transparency right in IE6 it has to be converted to a PNG8, and so, attached here is a small DOS command line tool called “pngquant.exe” that you should run with the following command line :
pngquant.exe 256 <filename.png>
The file : PNGquants
-
Another way, which is slightly more complicated, is to use Microsoft’s suggestion for the AlphaImageLoader filter, like in the following example :
<html>
<head></head>
<body bgColor=”blue”>
<!– This DIV is the target container for the image. –>
<DIV ID=”oDiv” STYLE=”position:absolute; left:140px; height:400; width:400;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
src=’image.png’, sizingMethod=’scale’);” >
</DIV>
</body>
</html>
Another method described in Galgal . Put the following in your <head>:
<!–[if gte IE 5.5000]>
<script language=”JavaScript”>
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()if (imgName.substring(imgName.length-3, imgName.length) == “PNG”)
{
var imgID = (img.id) ? “id=’” + img.id + “‘ ” : “”
var imgClass = (img.className) ? “class=’” + img.className + “‘ ” : “”
var imgTitle = (img.title) ? “title=’” + img.title + “‘ ” : “title=’” + img.alt + “‘ ”
var imgStyle = “display:inline-block;” + img.style.cssText
if (img.align == “left”) imgStyle = “float:left;” + imgStyle
if (img.align == “right”) imgStyle = “float:right;” + imgStyle
if (img.parentElement.href) imgStyle = “cursor:hand;” + imgStyle
var strNewHTML = “<span ” + imgID + imgClass + imgTitle
+ ” style=\”" + “width:” + img.width + “px; height:” + img.height + “px;”
+ imgStyle + “;” + “filter:progid:DXImageTransform.Microsoft.AlphaImageLoader”
+ “(src=\’” + img.src + “\’, sizingMethod=’scale’);\”></span>”
img.outerHTML = strNewHTML
i = i-1
}
}
}
window.attachEvent(”onload”, correctPNG);
</script>
<![endif]–>
Related posts:













