![]() |
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); })();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. |
Re: Resize images on page with javascript bookmarklet
try this
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) {if (document.images[i].width>800) zoomImage(document.images[i],.5);} if (!L) alert(%22This page contains no images.%22); })();---------- Post added at 13:53 ---------- Previous post was at 13:52 ---------- also if you want height taken into account you change just replace the bit with the width with Code:
(document.images[i].width>800 && document.images[i].height>400) |
Re: Resize images on page with javascript bookmarklet
Quote:
Quote:
|
Re: Resize images on page with javascript bookmarklet
|
Re: Resize images on page with javascript bookmarklet
Quote:
|
| All times are GMT +1. The time now is 23:13. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum