Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

png transparency

 
0
  #1
Apr 15th, 2008
does anyone no how to make an image in IE transparent?

my images work fine in Netscape/Firefox but display with white backgrounds in IE?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: png transparency

 
0
  #2
Apr 15th, 2008
i have just found this code is there away of doing this which does not use so much code.

i mean i can use this but i would rather learn the code myself for future use. (that is if MSIE decide to sort out this problem before it is needed again)

here is the code it goes on its own php page and only searches for images with .png extension.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. function replacePngTags($x,$img_path='',$sizeMeth='scale',$inScript=FALSE){
  3. $arr2=array();
  4. // make sure that we are only replacing for the Windows versions of Internet
  5. // Explorer 5.5+
  6. $msie='/msie\s(5\.[5-9]|[6]\.[0-9]*).*(win)/i';
  7. if( !isset($_SERVER['HTTP_USER_AGENT']) ||
  8. !preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
  9. preg_match('/opera/i',$_SERVER['HTTP_USER_AGENT']))
  10. return $x;
  11.  
  12. if($inScript){
  13. // first, I want to remove all scripts from the page...
  14. $saved_scripts=array();
  15. $placeholders=array();
  16. preg_match_all('`<script[^>]*>(.*)</script>`isU',$x,$scripts);
  17. for($i=0;$i<count($scripts[0]);$i++){
  18. $x=str_replace($scripts[0][$i],'replacePngTags_ScriptTag-'.$i,$x);
  19. $saved_scripts[]=$scripts[0][$i];
  20. $placeholders[]='replacePngTags_ScriptTag-'.$i;
  21. }
  22. }
  23.  
  24. // find all the png images in backgrounds
  25. preg_match_all('/background-image:\s*url\(([\\"\\\']?)([^\)]+\.png)\1\);/Uis',$x,$background);
  26. for($i=0;$i<count($background[0]);$i++){
  27. // simply replace:
  28. // "background-image: url('image.png');"
  29. // with:
  30. // "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(
  31. // enabled=true, sizingMethod=scale, src='image.png');"
  32. // I don't think that the background-repeat styles will work with this...
  33. $x=str_replace($background[0][$i],'filter:progid:DXImageTransform.'.
  34. 'Microsoft.AlphaImageLoader(enabled=true, sizingMethod='.$sizeMeth.
  35. ', src=\''.$background[2][$i].'\');',$x);
  36. }
  37.  
  38. // find all the IMG tags with ".png" in them
  39. $pattern='/<(input|img)[^>]*src=([\\"\\\']?)([^>]*\.png)\2[^>]*>/i';
  40. preg_match_all($pattern,$x,$images);
  41. for($num_images=0;$num_images<count($images[0]);$num_images++){
  42. // for each found image pattern
  43. $original=$images[0][$num_images];
  44. $quote=$images[2][$num_images];
  45. $atts=''; $width=0; $height=0; $modified=$original;
  46.  
  47. // We do this so that we can put our spacer.png image in the same
  48. // directory as the image - if a path wasn't passed to the function
  49. if(empty($img_path)){
  50. $tmp=split('[\\/]',$images[3][$num_images]);
  51. $this_img=array_pop($tmp);
  52. $img_path=join('/',$tmp);
  53. if(empty($img_path)){
  54. // this was a relative URI, image should be in this directory
  55. $tmp=split('[\\/]',$_SERVER['SCRIPT_NAME']);
  56. array_pop($tmp); // trash the script name, we only want the directory name
  57. $img_path=join('/',$tmp).'/';
  58. }else{
  59. $img_path.='/';
  60. }
  61. }else if(substr($img_path,-1)!='/'){
  62. // in case the supplied path didn't end with a /
  63. $img_path.='/';
  64. }
  65.  
  66. // If the size is defined by styles, find them
  67. preg_match_all(
  68. '/style=([\\"\\\']).*(\s?width:\s?([0-9]+(px|%));).*'.
  69. '(\s?height:\s?([0-9]+(px|%));).*\\1/Ui',
  70. $images[0][$num_images],$arr2);
  71. if(is_array($arr2) && count($arr2[0])){
  72. // size was defined by styles, get values
  73. $width=$arr2[3][0];
  74. $height=$arr2[6][0];
  75.  
  76. // remove the width and height from the style
  77. $stripper=str_replace(' ','\s','/('.$arr2[2][0].'|'.$arr2[5][0].')/');
  78. // Also remove any empty style tags
  79. $modified=preg_replace(
  80. '`style='.$arr2[1][0].$arr2[1][0].'`i',
  81. '',
  82. preg_replace($stripper,'',$modified));
  83. }else{
  84. // size was not defined by styles, get values from attributes
  85. preg_match_all('/width=([\\"\\\']?)([0-9%]+)\\1/i',$images[0][$num_images],$arr2);
  86. if(is_array($arr2) && count($arr2[0])){
  87. $width=$arr2[2][0];
  88. if(is_numeric($width))
  89. $width.='px';
  90.  
  91. // remove width from the tag
  92. $modified=str_replace($arr2[0][0],'',$modified);
  93. }
  94. preg_match_all('/height=([\\"\\\']?)([0-9%]+)\\1/i',$images[0][$num_images],$arr2);
  95. if(is_array($arr2) && count($arr2[0])){
  96. $height=$arr2[2][0];
  97. if(is_numeric($height))
  98. $height.='px';
  99.  
  100. // remove height from the tag
  101. $modified=str_replace($arr2[0][0],'',$modified);
  102. }
  103. }
  104.  
  105. if($width==0 || $height==0){
  106. // width and height not defined in HTML attributes or css style, try to get
  107. // them from the image itself
  108. // this does not work in all conditions... It is best to define width and
  109. // height in your img tag or with inline styles..
  110. if(file_exists($_SERVER['DOCUMENT_ROOT'].$img_path.$images[3][$num_images])){
  111. // image is on this filesystem, get width & height
  112. $size=getimagesize($_SERVER['DOCUMENT_ROOT'].$img_path.$images[3][$num_images]);
  113. $width=$size[0].'px';
  114. $height=$size[1].'px';
  115. }else if(file_exists($_SERVER['DOCUMENT_ROOT'].$images[3][$num_images])){
  116. // image is on this filesystem, get width & height
  117. $size=getimagesize($_SERVER['DOCUMENT_ROOT'].$images[3][$num_images]);
  118. $width=$size[0].'px';
  119. $height=$size[1].'px';
  120. }
  121. }
  122.  
  123. // end quote is already supplied by originial src attribute
  124. $replace_src_with=$quote.$img_path.'spacer.png'.$quote.' style="width: '.$width.
  125. '; height: '.$height.'; filter: progid:DXImageTransform.'.
  126. 'Microsoft.AlphaImageLoader(src=\''.$images[3][$num_images].'\', sizingMethod='.
  127. $sizeMeth.');"';
  128.  
  129. // now create the new tag from the old
  130. $new_tag=str_replace($quote.$images[3][$num_images].$quote,$replace_src_with,
  131. str_replace(' ',' ',$modified));
  132. // now place the new tag into the content
  133. $x=str_replace($original,$new_tag,$x);
  134. }
  135.  
  136. if($inScript){
  137. // before the return, put the script tags back in. (I was having problems when there was
  138. // javascript that had image tags for PNGs in it when using this function...
  139. $x=str_replace($placeholders,$saved_scripts,$x);
  140. }
  141.  
  142. return $x;
  143. }
  144. ?>

i found the code on this website i took all the copy right info off so it would display easier on this thread.

http://koivi.com/ie-png-transparency/
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 240
Reputation: Inny is an unknown quantity at this point 
Solved Threads: 6
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: png transparency

 
0
  #3
Apr 15th, 2008
or javascript

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <span class="ad_notxt"><code class="inlinecode">
  2. * Correctly handle PNG transparency in Win IE 5.5 & 6. http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006. Use in with DEFER keyword wrapped in conditional comments: */ var arVersion = navigator.appVersion.split("MSIE") var version = parseFloat(arVersion[1]) if ((version >= 5.5) && (document.body.filters)) { for(var i=0; i" img.outerHTML = strNewHTML i = i-1 } } } </code></span>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC