同事需要,就写了个插件 。。。。
原来我也写过两个,但这次是正式为jQuery写的插件。。。

$(document).ready(function(){
$('div').autoResize({height:50});
});

jQuery.fn.autoResize = function(options)
{
var opts = {
'width' : 400,
'height': 300
}
var opt = $.extend(true, {},opts,options || {});
width = opt.width;
height = opt.height;
$('img',this).each(function(){
var image = new Image();
image.src = $(this).attr('src');
//开始检查图片
if(image.width > 0 && image.height > 0 ){
var image_rate = 1;
if( (width / image.width) < (height / image.height)){
image_rate = width / image.width ;
}else{
image_rate = height / image.height ;
}
if ( image_rate <= 1){
$(this).width(image.width * image_rate);
$(this).height(image.height * image_rate);
}
}
});
}

原来的两篇在这里: