asp如何控制图片大小

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:37:38
想要图片最大500X500,小的图片长宽保持不变,超过这个大小的就变成500X500
该怎么做?

<img src="https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/img/logo-zhidao.gif" onload="if(parseInt(this.offsetWidth)>50)this.style.width='50px';">

此处演示为50;你改成500

<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 105/80){
if(image.width>105){
ImgD.width=105;
ImgD.height=(image.height*105)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt="显示信息..";
}
else{
if(image.height>80){
ImgD.height=80;
ImgD.width=(image.width*80)/image.he