如何使用服务器端vbscript获取图像宽度?ASP经典 [英] how to get image width with server-side vbscript? Asp classic

查看:57
本文介绍了如何使用服务器端vbscript获取图像宽度?ASP经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了好几天,以找到一种方法来获取驻留在我们服务器上的.png文件的图像宽度.我正在尝试读取文件的前24个字节,并从字节17-20解析出宽度.我在网上找到了一些例程,但没有成功.奇怪的是,看来我正在将21到24字节的高度从十六进制解码为十进制就好了.我已经使用十六进制查看器验证了文件内容,并且文件很好.这是例程的主要部分:

I have been trying for days to find a way to get the image width of .png files which reside on our server. I am trying to read the first 24 bytes of the file and parse out the width from bytes 17-20. I have found several routines on the web but have not been successful. Strangely enough, it seems I am getting the height from bytes 21-24 decoded from hex to decimal just fine. I have verified the file contents using a hex viewer and the file is good. Here is the main portion of the routine:

Function ReadPNG(fichero)
Dim fso, ts, s, HW, nbytes
    HW = Array("0", "0")
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.OpenTextFile(Server.MapPath("\forums\attachments/" & fichero), 1)
    s = Right(ts.Read(24), 8)
    HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
    HW(1) = HexToDec(HexAt(s,7) & HexAt(s,8))
    ts.Close
    ReadPNG = HW
End Function

Function HexAt(s, n)
    HexAt = Hex(AscAt(s, n))
End Function

Function HexToDec(ByVal HexVal)

Dim i, num, part
num = 0
For I = 1 to Len(HexVal)
    part = Mid(StrReverse(UCase(HexVal)), I, 1)
    If IsNumeric(part) Then
        num = num + (CInt(part) * 16 ^ (I - 1) )
    Else
        num = num + ( (Asc(part) - 55) * 16^(I - 1) )
    End If
Next

HexToDec = num

End Function

例如,我的文件的宽度字节为十六进制"00 00 01 80"(十进制384)在高字节中用十六进制"00 00 01 32"(十进制306)

As an example, my file has hex "00 00 01 80" in the width bytes (decimal 384) and hex "00 00 01 32" in the heigth bytes (decimal 306)

我得到的高度为306,但是宽度返回"0011"(十进制17).

I am getting the heigth 306 but thee width is returning "0011" (decimal 17).

我完全脚了!我也不必使用此例程.

I am totally stummped! I do not have to use this routine either.

谢谢,吉姆

推荐答案

这是我前一段时间看到的一则帖子,看起来它可能可以简化一些事情.我尚未测试,所以请告诉我您的结果.

Here is a post I saw awhile ago, looks like it could possibly simplify things a bit. I have not tested, so let me know your results.

<%
dim iWidth, iheight
sub ImgDimension(img)
dim myImg, fs
Set fs= CreateObject("Scripting.FileSystemObject")
if not fs.fileExists(img) then exit sub
set myImg = loadpicture(img)
iWidth = round(myImg.width / 26.4583)
iheight = round(myImg.height / 26.4583)
set myImg = nothing
end sub

ImgDimension(Server.MapPath("server image file"))
%> 

请参阅此处的帖子: http://www.haneng.com/asp-forum/ASP---Get-Image-Size_12971.html

更新:看到此方法不适用于64位.这是另一种替代方法的链接: http://www.4guysfromrolla.com/webtech/050300-1.shtml

UPDATE: Seeing that this method will not work in 64bit. Here is a link to another alternative method: http://www.4guysfromrolla.com/webtech/050300-1.shtml

这篇关于如何使用服务器端vbscript获取图像宽度?ASP经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆