js代码:

 

function pimsize(imgname,widths,heights){
var w;
var h;
//window.alert(picimg.width);
//window.alert(picimg.height);
w=imgname.width;
h=imgname.height;
if(imgname.width>widths){
do
w=w-1;
while (w>widths) ;

s=w/imgname.width;
//window.alert(s);
imgname.width=w;
imgname.height=h*s;
h=imgname.height
}
//window.alert(imgname.height);
//window.alert(heights);
if(imgname.height>heights){
do
h=h-1;
while (h>heights) ;

s=h/imgname.height;
//window.alert(s);
imgname.width=w*s;
imgname.height=heights;
}
}

 

html:

<img src="UpFiles/Product/2009522125252.jpg" id="pbigpic" border="0" align="absmiddle" onload="pimsize(this,320,310);" />

 

注:

asp.net 要在.cs文件这样写

this.pbigpic.Attributes.Add("onload", "pimsize(this,320,310);");

否则,生成失败.

posted on 2009-06-10 14:50  8user  阅读(309)  评论(0编辑  收藏  举报