16. august 2003 - 14:04
#8
<%
'Funktioner til at læse headere i grafik filerne: JPEG, PNG, GIF, BMP og WMF
Dim Size
Function AscAt(s, n)
AscAt = Asc(Mid(s, n, 1))
End Function
Function HexAt(s, n)
Dim lsH
lsH = Hex(AscAt(s, n))
If Len(lsH) <> 2 Then lsH = "0" & lsH
HexAt = lsH
End Function
Function isJPG(filen)
If inStr(uCase(filen), ".JPG") <> 0 Or inStr(uCase(filen), ".JPEG") <> 0 Then
isJPG = true
Else
isJPG = false
End If
End Function
Function isPNG(filen)
If inStr(uCase(filen), ".PNG") <> 0 Then
isPNG = true
Else
isPNG = false
End If
End Function
Function isGIF(filen)
If inStr(uCase(filen), ".GIF") <> 0 Then
isGIF = true
Else
isGIF = false
End If
End Function
Function isBMP(filen)
If inStr(uCase(filen), ".BMP") <> 0 Then
isBMP = true
Else
isBMP = false
End If
End Function
Function isWMF(filen)
If inStr(uCase(filen), ".WMF") <> 0 Then
isWMF = true
Else
isWMF = false
End If
End Function
Function isWebImg(f)
If isGIF(f) Or isJPG(f) Or isPNG(f) Or isBMP(f) Or isWMF(f) Then
isWebImg = true
Else
isWebImg = true
End If
End Function
Function ReadImg(filen)
If isGIF(filen) Then
ReadImg = ReadGIF(filen)
Else
If isJPG(filen) Then
ReadImg = ReadJPG(filen)
Else
If isPNG(filen) Then
ReadImg = ReadPNG(filen)
Else
If isBMP(filen) Then
ReadImg = ReadPNG(filen)
Else
If isWMF(filen) Then
ReadImg = ReadWMF(filen)
Else
ReadImg = Array(0,0)
End If
End If
End If
End If
End If
End Function
Sub Rep(s)
Response.Write s & "<BR>"
End Sub
Function ReadJPG(filen)
Dim fso, ts, s, HW, ns, n, ok
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(filen, 1)
ts.Skip(2)
ns = ts.Read(2)
Do While Not (ns = "ÿÀ" Or ns = "ÿÂ")
ns = ts.Read(2)
n = HexToDec(HexAt(ns,1) & HexAt(ns,2))
n = n - 2
ts.Skip(n)
ns = ts.Read(2)
Loop
ts.Skip(3)
s = ts.Read(4)
HW(0) = HexToDec(HexAt(s,3) & HexAt(s,4))
HW(1) = HexToDec(HexAt(s,1) & HexAt(s,2))
ts.Close
Set ts = Nothing
ReadJPG = HW
End Function
Function ReadPNG(filen)
Dim fso, ts, s, HW, nbytes
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 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 ReadGIF(filen)
Dim fso, ts, s, HW, nbytes
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
ts.Skip(6)
s = ts.Read(4)
HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
ts.Close
ReadGIF = HW
End Function
Function ReadWMF(filen)
Dim fso, ts, s, HW, nbytes
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
s = Right(ts.Read(14), 4)
HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
ts.Close
ReadWMF = HW
End Function
Function ReadBMP(filen)
Dim fso, ts, s, HW, nbytes
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(Server.MapPath("/" & filen), 1)
s = Right(ts.Read(24), 8)
HW(0) = HexToDec(HexAt(s,4) & HexAt(s,3))
HW(1) = HexToDec(HexAt(s,8) & HexAt(s,7))
ts.Close
ReadBMP = HW
End Function
Function isDigit(c)
If inStr("0123456789", c) <> 0 Then
isDigit = true
Else
isDigit = false
End If
End Function
Function isHex(c)
If inStr("0123456789ABCDEFabcdef", c) <> 0 Then
isHex = true
Else
ishex = false
End If
End Function
Function HexToDec(cadhex)
Dim n, i, ch, decimal
decimal = 0
n = Len(cadhex)
For i=1 To n
ch = Mid(cadhex, i, 1)
If isHex(ch) Then
decimal = decimal * 16
If isDigit(ch) Then
decimal = decimal + ch
Else
decimal = decimal + Asc(uCase(ch)) - Asc("A") + 10
End If
Else
HexToDec = -1
End If
Next
HexToDec = decimal
End Function
%>
21. januar 2004 - 08:18
#14
prøv at rette funktionen der hedder ReadGIF(filen) til dette her:
Function ReadGIF(filen)
Dim fso, ts, s, HW, nbytes
HW = Array("","")
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(filen, 1)
ts.Skip(6)
s = ts.Read(4)
HW(0) = HexToDec(HexAt(s,2) & HexAt(s,1))
HW(1) = HexToDec(HexAt(s,4) & HexAt(s,3))
ts.Close
ReadGIF = HW(0) & "*" & HW(1)
End Function