Auto-image Resizing

I’ve been using a variation of Clagnut-style liquid image-sizing in my blog, which works fine in IE and Firefox, but breaks because of Safari’s crappy image resizing.

Safari further confounds things by not allowing reliable post-hoc style removal via JS (sometimes it works, sometimes it doesn’t), and not appearing to support anything like image.naturalWidth to show the original sizes. So, here’s a fully JS solution (IE has problems with returning the parentNode.clientWidth so I just slap the old width/height styles on in that case):


function fit_blog_img() {
  if(!document.getElementById) return;
  if(!document.getElementsByTagName) return;

  var blog = document.getElementById("blog");
  var imgs = blog.getElementsByTagName("img");

  for(var i=0; i 1) {
      img.style.width = maxw + 'px';
      img.style.height = Math.floor(h/r) + 'px';
    }
  }
}

I’ll be doing some more bloggy hi-jinx in the near future. Looks I should get moving on releasing my rtedit modules…