Page 1 of 1
.png if else statement.
Posted: Thu Oct 08, 2009 1:02 pm
by Bjeffries111
I want to create a .png if else statement because I have noticed some browsers do not support .png files and I have almost finishes a site using .png. I dont like the quality of the .gif for what I am using this for.
I know how to write an if else statement but i do not know how to tel php to figure out if the browser supports .png transparency.
I am also not an expert with PHP, I have almost finished my PHP & MySQL for Dummies book so i have a lot to learn.
Thanks for the help,
Brian
Re: .png if else statement.
Posted: Fri Oct 09, 2009 2:17 am
by pa28
There is no way in PHP to 'ask' a browser whether it supports PHP -
McInfo's suggestion of looking at the user agent string and comparing it to your own database of supported browsers is the best you'll be able to do.
Having said that, the only modern browser I'm aware of that doesn't support transparent PNGs is MS Internet Explorer, versions prior to 7 IIRC. So:
Code: Select all
$pngSupport = true;
if(preg_match("/MSIE\s*(\d+)\./", $_SERVER['HTTP_USER_AGENT'], $matches)===1)
if((int)$matches[1]<7)
$pngSupport = false;
//If, by now, $pngSupport is still true, it's probably supported.
Re: .png if else statement.
Posted: Fri Oct 09, 2009 3:41 am
by onion2k
Re: .png if else statement.
Posted: Fri Oct 09, 2009 4:28 am
by snail
i think it cant
Re: .png if else statement.
Posted: Fri Oct 09, 2009 5:24 am
by onion2k
snail wrote:i think it cant
Really? Why not?
Re: .png if else statement.
Posted: Fri Oct 09, 2009 11:50 am
by desperado
This will enable transparency support:
Code: Select all
<script type="text/javascript">
if (typeof document.body.style.maxHeight != "undefined") {
// IE 7, mozilla, safari, opera 9
} else {
// IE6, older browsers
// alert( "In order to best experience this website, you should upgrade your copy of Internet Explorer to the latest version, or use Firefox or Safari." );
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (document.body.filters))
{
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>
Re: .png if else statement.
Posted: Fri Oct 09, 2009 12:16 pm
by Bjeffries111
I will try the code snippets that were offered and see if it works. Thanks for all the responses! hopefully something works!
Thanks,
Brian
Re: .png if else statement.
Posted: Fri Oct 09, 2009 5:54 pm
by Bjeffries111
I so far have tried all those code snippets and even tried that "iepngfix" css script but I still don't think it works. Although I am not directly seeing the results I am relying on another person to check for me from an older computer.
So i think I may just say screw it and replace the non important images with text and just leave the main images png for the people that can view png.
Brian