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
.png if else statement.
Moderator: General Moderators
Re: .png if else statement.
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:
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.
Every browser supports PNG. http://www.twinhelix.com/css/iepngfix/
Re: .png if else statement.
i think it cant
Re: .png if else statement.
Really? Why not?snail wrote:i think it cant
Re: .png if else statement.
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>
-
Bjeffries111
- Forum Newbie
- Posts: 11
- Joined: Thu Oct 08, 2009 12:56 pm
Re: .png if else statement.
I will try the code snippets that were offered and see if it works. Thanks for all the responses! hopefully something works!
Thanks,
Brian
Thanks,
Brian
-
Bjeffries111
- Forum Newbie
- Posts: 11
- Joined: Thu Oct 08, 2009 12:56 pm
Re: .png if else statement.
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
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