ASP 前台调用图片。如何限制显示长,宽?

来源:百度知道 编辑:UC知道 时间:2024/07/02 21:07:15
问题是,ASP调用图片,前台显示。
如果,后台提交的时候,图片是一张长和宽过于大。
那么前台显示的时候,版面就拉破了。

请问。我如何做,才能限制前台显示图片的长宽。或者是让显示的图片按原比例缩小。。。

思路:先获取图片长度和宽度,再定义一个最大的显示长度和宽度,当图片的长度或宽度大于最大长度或宽度时,等比例缩小图片尺寸.

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