发布网友
共1个回答
热心网友
给你例子可以参考
思路:先获取图片长度和宽度,再定义一个最大的显示长度和宽度,当图片的长度或宽度大于最大长度或宽度时,等比例缩小图片尺寸.
function getW(imgpath) '获得最终显示的图片宽度的函数
set pp=new imgInfo
w = pp.imgW(server.mappath(imgpath)) 'imgpath就是通过ASP从数据库中获得的图片路径
h = pp.imgH(server.mappath(imgpath))
wtoh=w/h '获得图片原尺寸的长宽比
dim ww,hh
if w>=150 and h>=150 then '这里定义一个最大长和宽 150
if w>=h then
ww=150
hh=ww/wtoh
getW=ww
else
hh=150
ww=hh*wtoh
getW=ww
end if
else
ww=w
hh=h
getW=ww
end if
set pp=nothing
end function
function getH(imgpath) '获得最终显示的图片长度的函数
set pp=new imgInfo
w = pp.imgW(server.mappath(imgpath))
h = pp.imgH(server.mappath(imgpath))
wtoh=w/h
dim ww,hh
if w>=150 and h>=150 then
if w>=h then
ww=150
hh=ww/wtoh
getH=hh
else
hh=150
ww=hh*wtoh
getH=hh
end if
else
ww=w
hh=h
getH=hh
end if
set pp=nothing
end function
function getP(imgpath) '获得图片路径的函数
getP=imgpath
end function
response.write "<img src='"&getP("图片路径可以由ASP动态生成")&"' border=0 width='"&getW("图片路径可以由ASP动态生成")&"' heidth='"&getH("图片路径可以由ASP动态生成")&"'>"