Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Image scaling in IE6 and 7 is bobbins. This script uses Microsoft's proprietary filter gubbins to make it better.
Image scaling in IE6 and 7 is bobbins. This uses their proprietary filter gubbins to make it better.
Original by Ethan Marcotte, at
Rejigged by Olly Hodgson.
So Ethan [@beep] wrote a script that'll make IE6 and 7 on Windows resize
images beautifully []
(without the performance hit you take from using -ms-interpolation-mode:
bicubic;). Tom H pointed out in the comments that it broke the right-click
and save functionality. This was acceptable to Ethan, but it bugged me.
So I set about tearing Ethan's original apart. I'm a jQuery monkey so I
used that, instead of the straight JS he used.
# Clones the original image
# Positions the clone over the top of the original, then sets it's opacity
to 0. That way, you can right-click and save it (etc) but see though it
# Then it does the fancy rescaler stuff to the original image
# On resize it re-does the fancy stuff
Olly Hodgson, May 2009.
Originally posted to:
function imgResizer () {
$(".IE6 img:not(.clone), .IE7 img:not(.clone)").each(function (i) {
var currentImg, currentClone, currentCloneId, currentWidth, currentHeight;
currentImg = $(this);
/* Wrap a span around the original image to help with positioning */
if (!$(currentImg).parent().hasClass("imgWrapper")) {
$(currentImg).wrap("<span class='imgWrapper'></span>");
$(currentImg).attr("id", "original" + i);
/* Figure out if this image has a clone, and if not, clone it. */
currentCloneId = "#clone" + $(currentImg).attr("id").substring(8);
if ($(currentCloneId).length === 0) {
$(currentImg).clone().insertAfter(currentImg).addClass("clone").css({"position" : "absolute", "top" : "0", "left" : "0", "opacity" : "0" }).attr("id", "clone" + i);
/* Remove these so screenr reader users don't get them twice */
$(currentImg).attr("alt", "");
$(currentImg).attr("title", "");
currentClone = $(currentCloneId);
/* Set the original img src to that of the clone */
if ($(currentImg).attr("src") != $(currentClone).attr("src")) {
$(currentImg).attr("src", $(currentClone).attr("src"));
/* Resize it accordingly */
currentWidth = currentImg[0].clientWidth;
currentHeight = currentImg[0].clientHeight;
/* Now apply the filter and put the transparent gif back */
currentImg[0].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + currentImg[0].src + "', sizingMethod='scale')";
currentImg[0].src = "x.gif";
/* Now set the height on both the original and it's clone */
These functions are fired as soon as the DOM is ready
$(document).ready(function () {
/* Check we're in IE6 or 6 - see the conditional comments in the <body> */
if ($(".IE6, .IE7").length > 0) {

This comment has been minimized.

Copy link
Owner Author

@OllyHodgson OllyHodgson commented Jun 23, 2015

Funny to think what a pressing problem this was 6 years ago, and how the script seems utterly irrelevant today 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.