Submitted by alienbrain on Sun, 10/04/2005 - 15:24.
( categories: )

Hello,

Last night, I opened eglug.org on an internet cyber with an IE browser. And I was shocked with how the PNGs look shitty on it.

This is a solution I came up with today. It will give the browser GIFs when it's IE otherwise it will give it PNGs.

Place this script in your drupal root. Then all you need to do is, replacing your img paths with something like "image.php?name=logo"

so a previous img tag was like

<img src="/themes/eglug/logo.png" ...more attribs>
should become like
<img src="/image.php?name=logo" ..more attribs>

For example,
To add this functionality to your drupal-powered logo image you need to:
1. Go to Administer -> Themes -> Configure
2. In "Path to custom logo:" field, put "image.php?name=logo" where logo is your logo image name of course.
3. Scroll down and hit Save Configuration.

That solution is not that flexible and doesn't integrate into drupal nicely. I was hopping to write a better solution that will fit into drupal like a filter or a module, but from a quick look into drupal, I realized this is not possible.

So everyone is very welcomed to write a better implementation of it.

I've got some more other stuff to put into it in order to make it more flexible. However, I needed to know if the idea itself is accepted and can be used or not so I can put further development time on it.


- Amr

Attached "image.php":


/**
 * Copyright (c) Amr Mostafa
 * This stuff is GPL v2 licensed, so feel free to use it in anyway.
 */

/* change this to wherever your images are */
$prefix = "themes/eglug";

if (!isset($_GET['name'])) {
  exit;
}

$name = $_GET['name'];

/* should this be a regexp ? strpos is lot faster anyway */

if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
  $image_ext = "gif";
  $content_type = "image/gif";
}
else {
  $image_ext = "png";
  $content_type = "image/png";
}

$prefix = rtrim($prefix, "/");
$image_path = sprintf("%s/%s.%s", $prefix, $name, $image_ext);

/**
 * The following block of code will make sure that even if a .gif or a .png file doesn't exist
 * the other file will be used.
 * So you can safely remove those next 16 lines of code if you don't need this functionality :-)
 */
if (!file_exists($image_path)) {
  if ($image_ext == "gif") {
    $image_ext = "png";
    $image_path = sprintf("%s/%s.%s", $prefix, $name, $image_ext);
    if (!file_exists($image_path)) {
      exit;
    }
  }
  else {
    $image_ext = "gif";
    $image_path = sprintf("%s/%s.%s", $prefix, $name, $image_ext);
    if (!file_exists($image_path)) {
      exit;
    }
  }
}

//$gmt_date = gmdate("D, d M Y H:i:s") . " GMT";
$size = filesize($image_path);

$fp = fopen($image_path, "rb");
if (!$fp) {
  exit;
}

//header("Date: " . $gmt_date);
header("Content-Type: " . $content_type);
header("Content-Length: " . $size);
fpassthru($fp);
exit;

amr

whirlpool's picture

Thanks for the code ya Amr but this is not our problem. PNG is a w3c recommendation since 1996. It's one of the many things that Internet Explorer sucks at.

It's IE developers problem and not us. And IE users should use a better browser.

I did comment on this before. And here is Alaa's reply.


Mostafa Hussein

thanx for the contrib

Alaa's picture

I still believe we should not accomodate IE except where the site is completly broken.

but this piece of code is still of useful, please next time submit code and stuff like that as book pages (aka wiki pages) so others can edit them, keep the forum for discussion only where collaborative editing makes no sense.

cheers,
Alaa


http://www.manalaa.net "i`m feeling for the 2nd time like alice in wonderland reading el wafd"

you are right

You have got pretty good points guys.

But then, I think we should make it clear that this website is "best viewed with put-a-good-browser-here".

Otherwise, have a nice day!

-Amr

important point

linuxawy's picture

i guess it's a good idea to put such a hint.. most of window$ users think that the prob. is in the site.. they should know it's their problem..

Ahmed D. El-Mekkawy

  • I was known as Black Cat

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.