Asp无组件生成缩略图 (3)

80酷酷网    80kuku.com

  缩略图|无组件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语句实现,具体编码就不再累述了。

  这样,一个无组件生成缩略图程序就写好了,可能有点拿来主义,不过只要大家能将方法掌握相信还是有很大提高的。

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: