Shady Spot

Posts

Sunday, August 14, 2005

Image Resizer Script

Automatic Image Resizer: JavaScript function fixImgs()

This script resizes all images that exceed the preset maximum width (360 pixels for this template) while maintaining aspect ratio. I created it to prevent very wide pictures from breaking the column style.

The picture below measures 432 x 324 pixels at source. If left unchecked, the body of this post will stretch beyond this column of 425 pixels. The script reduced the image to 360 x 270 pixels, thus preserving the column width specification.

sample large picture

Image Resizer code below:
<script type="text/javascript"><!--
function fixImgs() {
var maxW=360;
for (i=0; i < document.images.length; i++) {
w=document.images[i].width;
h=document.images[i].height;
if (w>maxW) {
f=1-((w-maxW)/w);
document.images[i].width=(w*f);
document.images[i].height=(h*f);
}
}
}
--></script>

View template code with resizer script (opens new window)

posted by Cat at 2:27 PM

About Me

Name: Cat
Location: Mandaluyong City, Metro Manila, Philippines

View my complete profile

Previous Posts

  • My Birthday Gift to Her
  • Moon in Cancer: Sanctuary of the Heart
  • How Does Your Cat Love Thee?

Archives

My CBox

  • Drop me a note!

Get Firefox!

Weblog Commenting and Trackback by HaloScan.com

Powered by Blogger

Valid HTML 

4.01 Transitional

Return

C a t m a d e i t !