PNG Transparency, IE PNG Transparency

This is a simple script to properly render png images in IE and standards compliant browsers. It works differently than the other png programs I’ve found out there.

Typically you use a php session and have php find and replace the png images with the extra garbage that IE needs to render transparency, it works but not that well especially when talking about background-image png’s. I’ve taken a different approach. Rather than buffering the page in a session and having the server work hard to swap everything and render the page I’ve gone with an in-line approach.

First include the file png-img.php before the head of your document, oh you have to have .htaccess override enabled so you can include php in your .html files otherwise you have to go with .php files so this php script will run.

Second when coding an image into your page; rather than the traditional <img> tag, we are going to use a php echo instead. <?php echo png_img(‘img or bkg’,’/path/to/file.png’,’width’,’height’,’border’,’IE style’,’style all browsers’,’id’,’align’);?>  so when the page is rendered it will detect the browser and write the appropriate <img> tag dependent upon the useragent of the browser. The nice thing is you can specify a different style for IE than the other browsers, also you can use it for bkg png’s, by default they are scaled, however with a simple php str_replace you can set that to whatever you want. Also since it’s simple php with html it’s easy to update with any feature you would want to add later.

PNG Image [PHP Script]

Tags: , , ,

Comments are closed.