03 Jul 2004

Ever biched over IE not being able to use transparent PNG’s?

Posted by Jacob Emcken

Well I have!!

Some days ago I found a link to a hack on Jakub ‘jimmac’ Steiner’s homepage.

I have now made a function in PHP which automaticaly uses this workaround in IE. Take a look at the code below.

$localDocumentRoot = str_replace($_SERVER['PHP_SELF'],
"", $_SERVER['SCRIPT_FILENAME']);

//$image is an array
/* This is a hack to use PNG transparentsy in IE */
function transparentImage($image, $ie) {
  global $localDocumentRoot;
  //The str_replace makes sure that images with spaces is also recognized
  $imageFile = getimagesize( str_replace(' ','%20',
  $localDocumentRoot.$image['src'] ) );
  if($ie) {
?>
<div
<?=((isset($image['id'])) ? ' id="'.$image[id].'"' : '')?>
<?=((isset($image['class'])) ? ' class="'.$image['class'].'"' : '')?>
style="<?=' height:'.$imageFile[1].'px;'?> filter:progid:DXImageTransform.Microsoft.\AlphaImageLoader(src='',
sizingMethod='scale');" > </div>
<?php
  }
  else {
?>
<img src="<?=$image['src']?>"
<?=((isset($image['id'])) ? ' id="'.$image['id'].'"' : '')?>
<?=((isset($image['class'])) ? ' class="'.$image['class'].'"' : '')?>
<?=((isset($image['alt'])) ? ' alt="'.$image['alt'].'"' : '')?>
 width="<?=$imageFile[0]?>"
 height="<?=$imageFile[1]?>"
<?=((isset($image['title'])) ? ' title="'.$image['title'].'"' : '')?>
/>
<?php
  }
}
?>

//Now run the function
$image['src'] = "/gallery/image.png";
$image['id'] = "unique_image";
$image['class'] = "image";
$image['alt'] = "Image example with transparent PNG images";
$image['title'] = "Tooltip for image";

transparentImage($image, true);

Tomorrow I will take a look at this post to make sure that I havet posted shitty code ;) Perhapes I can find a way so that Serendipity doesn’t fuck with the layout?!

No comments yet.

Leave a comment