I found a great article in alistapart.com on this issue (hope it's not absolutely outdated- Cross-Browser Variable Opacity with PNG: A Real Solution http://www.alistapart.com/articles/pngopacity
I'm not sure which approch is the most suitable for Drupal and web standarts at the same time.
Anyone solved this one?

Comments

Steve Dondley’s picture

Just put the following code in a file in your modules directory:


function iepng_filter_help($section) {
  switch ($section) {
    case 'admin/modules#description':
      return t("Fixes bug in Interner Explorer so transparent .png images will show as transparent.");
  }
}

function iepng_filter_filter_tips($delta, $format, $long = false) {
  return t('Install this module to restore .png file transparency in Internet Explorer.');
}

function iepng_filter_filter($op, $delta = 0, $format = -1, $x = '') {
  switch ($op) {
    case 'list':
      return array(0 => t("IE .png filter"));

    case 'description':
      return t("Fixes bug in Interner Explorer so transparent .png images will show as transparent.");

    case 'process':
      $arr2=array();
      global $base_url;
      $parsed_url = parse_url($base_url);
      $base_dir = $parsed_url['path'];
      // make sure that we are only replacing for the Windows versions of Internet
      // Explorer 5+
      $msie='/msie\s([5-9])\.?[0-9]*.*(win)/i';
      if(!isset($_SERVER['HTTP_USER_AGENT']) ||
          !preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
          preg_match('/opera/i',$_SERVER['HTTP_USER_AGENT']))
          return $x;
 
      // OK, time to find all the IMG tags with ".png" in them
      preg_match_all('/<.*?img.*\.png(\\\'|\\").*>/Ui', $x, $images);
      for($num_images=0; $num_images < count($images[0]); $num_images++) {
          $original = $images[0][$num_images];
          $quote = $images[1][$num_images];
          preg_match_all('/src=(\\\'|\\")([^\"]+\.png)\\1/i', $images[0][$num_images], $arr2);
          if(isset($arr2[2][0]) && !empty($arr2[1][0])) {
            $image = $arr2[2][0];
            $parsed_url = parse_url($image);
            if ($parsed_url['host']) {
              $image = $parsed_url['path'];
            }
            else {
              $image = $base_dir . "/$image";
            }
          }
          else {
            $image=NULL;
          }
         $replace_src_with=$base_dir . '/themes/xtemplate/custom/null.gif' . $quote . ' style="filter: progid:DXImageTransform.' . 'Microsoft.AlphaImageLoader(src=\'' . $image . '\', sizingMethod=' . '\'image\');"';
          
          // now create the new tag from the old
         $new_tag = str_replace($image . $quote, $replace_src_with, $original);
          
         // now place the new tag into the content
         $x = str_replace($original, $new_tag, $x);
      }
      return $x;

    default:
      return $x;
  }
}


Make sure you enable the module and enable the filter for the different filter types or it won't do anything.

msurdi’s picture

Hi, I've installed this modulo and set it up (enabled & activates as filter for all formats) but my webpage logo stills displays a white background isntead of a transparent one as it should be.

¿is this module just for nodes, comments, etc??

Thanks.

Steve Dondley’s picture

Only nodes and comments. If you do some research on google, you can figure out how to do this for the entire page. I have done it before and with Drupal. I've forgotten the details, however. Sorry.

--
Get better help from Drupal's forums and read this.

elpedro’s picture

Hi,

I've just started on drupal, and I'm totaly new to CMS & CSS. First thing I tried was to edit an existing theme to my need, when I stumbled on the 'transparency' bug in IE. This module looks like it might help me out, but I can't figure out how to implement/use it.

Any help is welcome

Steve Dondley’s picture

Go to Drupal's "modules" directory.

1) Create a new file called iepng_filter.module and cut and paste the code above into it.
2) Activate the new module in admin -> modules
3) Activate the filter by going to admin -> input formats
4) Click configure for each of the input formats you wish to add the new filter to.
5) Enable the new filter by checking the box.

--
Get better help from Drupal's forums and read this.

elpedro’s picture

That did the trick.....

Thanks

rkerr’s picture

I have just used an external javascript file incorporated into custom themes, but you could maybe use a module that adds the javascript link into the html head with drupal_set_html_head().

Then the png fix is executed by the client and applies to all pngs on the page. A drawback is sometimes there is a bit of flicker as the images are drawn with the wrong background, and then replaced with the corrected filtered version.

peteratomic’s picture

wish this worked with Version 6

WorldFallz’s picture

always check the modules.....

http://drupal.org/project/pngfix

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz