View Single Post
Old 26-10-2007, 14:37   #1
Alien
Inactive
 
Alien's Avatar
 
Join Date: Jul 2003
Location: UK
Services: VM Phone, V+, VM 10Mb
Posts: 2,655
Alien is cast in bronzeAlien is cast in bronzeAlien is cast in bronzeAlien is cast in bronze
Alien is cast in bronzeAlien is cast in bronzeAlien is cast in bronzeAlien is cast in bronzeAlien is cast in bronzeAlien is cast in bronzeAlien is cast in bronze
Resize images on page with javascript bookmarklet

I don't really have a head for coding, but I need a bit of javascript modified. I was wondering if perhaps someone might know how to change it to get the desired result.

What I have at the moment is a "bookmarklet" that rescales/shrinks images on a page. It's useful for when people post images that are too large on forums, etc. The 1 problem with it is that it appears to shrink all images on the page, not just the ones that are too large.
Heres what I have.
Code:
javascript:(function(){ function zoomImage(image, amt) { if(image.initialHeight == null) { /* avoid accumulating integer-rounding error */ image.initialHeight=image.height; image.initialWidth=image.width; image.scalingFactor=1; } image.scalingFactor*=amt; image.width=image.scalingFactor*image.initialWidth; image.height=image.scalingFactor*image.initialHeight; } var i,L=document.images.length; for (i=0;i<L;++i) zoomImage(document.images[i],.5); if (!L) alert(%22This page contains no images.%22); })();
The .5 in the code seems to be a scaling factor, which I've experimented with, & .75 seems to be better, as it's not often that posted images are twice as wide as they should be to fit on a page without making the page wider than the window.

I'm guessing the simplest way to do it would be some sort of image width check, & only resize images with a width => a set limit [e.g. 800]. If anyone can help it would be appreciated.
Alien is offline   Reply With Quote