Show only 100px square portion of an image?


I’m not entirely sure javascript is the route for this, but I can’t seem to figure out another way. Basically, what I’m trying to achieve is create a 100px by 100px square thumbnail of an image that can be clicked on to display the actual, full sized image. Now, the problem is, the full sized images are people uploaded by any visitor to the site, so they won’t always be perfect squares where I would be able to just define a width and height. In order to keep with the layout, I need the 100px by 100px thumbnail, so I’m wondering what would be the best way to acheive this when all the uploaded full sized images may not be perfect squares where they could jsut be resized.

If you’re still not sure what I mean, here’s a quick example:

A user uploads a picture that is 1200x983px, but the thumbnail for this picture must be 100x100px. If I were to just do something like <img height=“100px” width=“100px” />, the image would be all distorted since a perfectly square photo was not used, and if I were to just define a width of 100px only, the height may not be 100px.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="" xml:lang="en" lang="en">

<style type="text/css">

.thumb {
  position:relative;width:100px;height:100px;border:solid red 1px;


<div class="thumb" >
 <img src="" width="263" height=351"/>
<div class="thumb" >
 <img src="" width="263" height=351"/>

<script type="text/javascript">

function ResizeThumbs(cls,sz){
 var ds=document.getElementsByTagName('DIV'),a,img,z0=0;
 for (;z0<ds.length;z0++){
  if (img&&(' '+ds[z0].className+' ').match(' '+cls+' ')){
   a=[img,ds[z0],new Image(),sz];


function ResizeLoad(a){
 if (a[2].width<40){
  a[4]=setTimeout(function(){ ResizeLoad(a); },200);
 else {
  var w=a[2].width,h=a[2].height,ra=w>=h?['height','width',a[3]/h,h,w,'left','top']:['width','height',a[3]/w,w,h,'top','left'];



Wow, thanks a lot, it works great.