Domain Discussion Board

Go Back   Domain Discussion Board > Web Hosting & Web Design > Scripts

 
Reply
 
LinkBack Thread Tools Display Modes
Transparent PNGs
Old
  (#1 (permalink))
theDragonsDen
Executive Member
theDragonsDen is an unknown quantity at this point
 
theDragonsDen's Avatar
 
Status: Offline
Posts: 232
Points: 50.0
Bank: 821.0
Total Points: 871.1
Donate
Join Date: Nov 2006
Rep Power: 0
Transparent PNGs - 11-10-2006, 03:29 PM

In IE 6 and lower, the only way to make your image transparent is to save it as gif. PNG is a larger filetype which preserves colors better than any other image type. PNG also has supports transparency and better than gif because it supports percentage transparency unlike gif.

However IE6 and lower dont support PNG transparency. In IE 7 this is fixed but a majority of people dont have it yet. Take a look below.
GIF --> PNG -->

You cant really see it too good but if the gif were against a dark background it would be choppy If u highlight it u can see it better. The PNG bg should be transparent (if u have IE7) or have a grey bg if not.

This script makes it so ur image is transparent and doesnt have a choppy outside.

Javascript below
Code:
/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.
Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
*/
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
      }
   }
}
As it says in the note at the top of the script, put
Code:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->
between the <head> tags because IE7 is fixed for PNGs.


...
   
Reply With Quote
Re: Transparent PNGs
Old
  (#2 (permalink))
artoonie
Platinum Member
artoonie is an unknown quantity at this point
 
artoonie's Avatar
 
Status: Offline
Posts: 909
Points: 1,027.1
Bank: 3,294.2
Total Points: 4,321.3
Donate
Join Date: Nov 2006
Location: Here and there
Rep Power: 0
Re: Transparent PNGs - 11-10-2006, 03:45 PM

Hey, that's really awesome, thanks! I'll try it out right now :]
   





Reply With Quote
Sponsored Links
Re: Transparent PNGs
Old
  (#3 (permalink))
theDragonsDen
Executive Member
theDragonsDen is an unknown quantity at this point
 
theDragonsDen's Avatar
 
Status: Offline
Posts: 232
Points: 50.0
Bank: 821.0
Total Points: 871.1
Donate
Join Date: Nov 2006
Rep Power: 0
Re: Transparent PNGs - 11-10-2006, 04:07 PM

No problem artoonie. I thought this was great when I found it too. I wish I had found out about this a long time ago after I spent alot of time making all the transparencies to find out it didnt work on the internet. Oh well.


...
   
Reply With Quote
Re: Transparent PNGs
Old
  (#4 (permalink))
artoonie
Platinum Member
artoonie is an unknown quantity at this point
 
artoonie's Avatar
 
Status: Offline
Posts: 909
Points: 1,027.1
Bank: 3,294.2
Total Points: 4,321.3
Donate
Join Date: Nov 2006
Location: Here and there
Rep Power: 0
Re: Transparent PNGs - 11-10-2006, 04:17 PM

I used to have to print-screen the background and put it around my image =/
   





Reply With Quote
Re: Transparent PNGs
Old
  (#5 (permalink))
Mark10
Senior Member
Mark10 is on a distinguished road
 
Mark10's Avatar
 
Status: Offline
Posts: 239
Points: 150.2
Bank: 4,779.3
Total Points: 4,929.5
Donate
Join Date: Nov 2006
Location: Australia
Rep Power: 3
Re: Transparent PNGs - 11-10-2006, 11:39 PM

This was really useful. Thanks for that, I'm going to test it out right away!


Stuck with something? I may be able to help out. Drop me a PM and I'll do my best to help with your problems.
   
Reply With Quote
Re: Transparent PNGs
Old
  (#6 (permalink))
tommya24
Member
tommya24 is on a distinguished road
 
tommya24's Avatar
 
Status: Offline
Posts: 50
Points: 53.4
Bank: 1,435.0
Total Points: 1,488.4
Donate
Join Date: Nov 2006
Rep Power: 0
Re: Transparent PNGs - 11-11-2006, 08:18 AM

so useful
thx very much to you
   
Reply With Quote
Re: Transparent PNGs
Old
  (#7 (permalink))
theDragonsDen
Executive Member
theDragonsDen is an unknown quantity at this point
 
theDragonsDen's Avatar
 
Status: Offline
Posts: 232
Points: 50.0
Bank: 821.0
Total Points: 871.1
Donate
Join Date: Nov 2006
Rep Power: 0
Re: Transparent PNGs - 11-11-2006, 09:03 AM

Glad I could be of help to u mark and tommy. feel free to click on the star on the left to add to my reputation.


...
   
Reply With Quote
Re: Transparent PNGs
Old
  (#8 (permalink))
Kurosaki Ichigo
Platinum Member
Kurosaki Ichigo is an unknown quantity at this point
 
Kurosaki Ichigo's Avatar
 
Status: Offline
Posts: 547
Points: 554.9
Bank: 1,112.3
Total Points: 1,667.2
Donate
Join Date: Nov 2006
Location: UK
Rep Power: 0
Re: Transparent PNGs - 11-17-2006, 04:23 PM

Very nice. I was wondering how it didnt work.
   
Reply With Quote
Re: Transparent PNGs
Old
  (#9 (permalink))
hariharan
Platinum Member
hariharan is an unknown quantity at this point
 
hariharan's Avatar
 
Status: Offline
Posts: 496
Points: 60.9
Bank: 371.1
Total Points: 432.0
Donate
Join Date: Oct 2006
Location: India
Rep Power: 0
Re: Transparent PNGs - 11-18-2006, 07:42 PM

Awesome buddy.. Great piece of code.. Adding reputation to you..


Advertise your site in this exclusive place.Each slot costs 40 ddPoints per week.

To get your ad displayed in my Avatar, you can make a GIF and give it to me. Dimensions: 75x75 pixels. Only for 60 ddPoints per week!

   
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 0.1
Points Per Thread: 15.0
Points Per Reply: 5.0



Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 ©2007, Crawlability, Inc.