Skip to Content

PNGs with IE issue

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"

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;
whirlpool's picture

amr


Alaa's picture

thanx for the contrib

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.

Alaa


"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

linuxawy's picture

important point

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.


Dr. Radut | forum