您的位置:首页 > 编程语言 > ASP

Asp无组件生成缩略图 [3]

2005-10-13 13:12 447 查看
3.定义缩略图尺寸

  这部分代码就是仁者见仁,智者见智了。首先,我们需要规定缩略图显示尺寸范围,譬如:300X260,代码可以这样写:
<%
Dim PXWidth,PXHeight
Dim Pp '//Proportion
If PWidth=0 Or PWidth="" Then
PXWidth=0
PXHeight=0
Else
Pp=FormatNumber(PWidth/PHeight,2) '//长宽比
End If
If PWidth>=PHeight Then
If PWidth>=300 Then
PXWidth=300
PXHeight=FormatNumber(300/Pp,0)
Else
PXWidth=PWidth
PXHeight=PHeight
End If
Else
If PHeight>=260 Then
PXHeight=260
PXWidth=FormatNumber(260*Pp,0)
Else
PXWidth=PWidth
PXHeight=PHeight
End If
End If
%>
  将上面的代码紧接第二步写下即可。调用时代码如下:
<img src=<%=curfilename%> border="0" width=<%=PXWidth%>
height=<%=PXHeight%>>
  至于图片格式可以用得到,图片尺寸可以写成
<%
response.write PXWidth&"X"&PXHeight
%>
  图片大小可以用FSO.GetFileSize(filename)来实现,而点击次数可以简单地用SQL语句实现,具体编码就不再累述了。
  这样,一个无组件生成缩略图程序就写好了,可能有点拿来主义,不过只要大家能将方法掌握相信还是有很大提高的。

  这部分代码就是仁者见仁,智者见智了。首先,我们需要规定缩略图显示尺寸范围,譬如:300X260,代码可以这样写:
<%
Dim PXWidth,PXHeight
Dim Pp '//Proportion
If PWidth=0 Or PWidth="" Then
PXWidth=0
PXHeight=0
Else
Pp=FormatNumber(PWidth/PHeight,2) '//长宽比
End If
If PWidth>=PHeight Then
If PWidth>=300 Then
PXWidth=300
PXHeight=FormatNumber(300/Pp,0)
Else
PXWidth=PWidth
PXHeight=PHeight
End If
Else
If PHeight>=260 Then
PXHeight=260
PXWidth=FormatNumber(260*Pp,0)
Else
PXWidth=PWidth
PXHeight=PHeight
End If
End If
%>
  将上面的代码紧接第二步写下即可。调用时代码如下:
<img src=<%=curfilename%> border="0" width=<%=PXWidth%>
height=<%=PXHeight%>>
  至于图片格式可以用得到,图片尺寸可以写成
<%
response.write PXWidth&"X"&PXHeight
%>
  图片大小可以用FSO.GetFileSize(filename)来实现,而点击次数可以简单地用SQL语句实现,具体编码就不再累述了。
  这样,一个无组件生成缩略图程序就写好了,可能有点拿来主义,不过只要大家能将方法掌握相信还是有很大提高的。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  asp border sql