1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
| <%
Class AVEImgClass
' Global Variables
Dim p_Height
Dim p_Width
Dim p_Depth
Dim p_ImageType
Dim p_FilePhysicalPath
' Initialize
Public Sub Class_Initialize()
Me.SetWidth = -1
Me.SetHeight = -1
Me.SetDepth = -1
Me.SetImageType = "UNKNOWN"
End Sub
' Class Properties
Public Property Let SetHeight(inHeight)
p_Height = inHeight
End Property
Public Property Let SetWidth(inWidth)
p_Width = inWidth
End Property
Public Property Let SetDepth(inDepth)
p_Depth = inDepth
End Property
Public Property Let SetImageType(inImageType)
p_ImageType = inImageType
End Property
Public Property Let SetFilePhysicalPath(inFilePhysicalPath)
p_FilePhysicalPath = inFilePhysicalPath
End Property
Public Property Get GetHeight()
GetHeight = p_Height
End Property
Public Property Get GetWidth()
GetWidth = p_Width
End Property
Public Property Get GetDepth()
GetDepth = p_Depth
End Property
Public Property Get GetImageType()
GetImageType = p_ImageType
End Property
Public Property Get GetFilePhysicalPath()
GetFilePhysicalPath = p_FilePhysicalPath
End Property
' Class Functions
' The following two functions converts two bytes
' to a numeric value (long)
Public Function LittleEndian(inBytes)
LittleEndian = CLng(Asc(Left(inBytes, 1))) + (Asc(Right(inBytes, 1)) * 256)
End Function
Public Function BigEndian(inBytes)
BigEndian = CLng(Asc(Right(inBytes, 1))) + (Asc(Left(inBytes, 1)) * 256)
End Function
Public Function GetBytes(inFile, inOffset, inBytes)
' This function gets a specified number of bytes from
' any file, starting at the passed offset
' Three parameters :
' - inFile : File physical path to read
' - inOffset : Offset at which to start reading
' - inBytes : Number of bytes to read (if -1 then ReadAll)
Dim oFSO
Dim oFile
Dim FileSize
Dim FSOForReading
Dim s_Buffer
On Error Resume Next
' We get the file size
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oFile = oFSO.GetFile(inFile)
FileSize = oFile.Size
Set oFile = Nothing
' We read the file from inOffset
FSOForReading = 1
Set oFile = oFSO.OpenTextFile(inFile, FSOForReading)
If inOffset > 0 Then
s_Buffer = oFile.Read(inOffset - 1)
End If
If inBytes = -1 Then
' Read All
s_Buffer = oFile.Read(FileSize)
Else
s_Buffer = oFile.Read(inBytes)
End If
oFile.Close
Set oFile = Nothing
Set oFSO = Nothing
GetBytes = s_Buffer
End Function
Public Sub GetFileSpec()
' This sub will run the process and set all the properties
Dim FilePath
Dim s_PNG
Dim s_GIF
Dim s_BMP
Dim s_Type
Dim s_Depth
Dim s_Buffer
Dim BufferSize
Dim FlagFound
Dim s_Search
Dim ExitLoop
' We get the file physical path
FilePath = Me.GetFilePhysicalPath
' Let's set Images Types
s_PNG = Chr(137) & Chr(80) & Chr(78)
s_GIF = "GIF"
s_BMP = Chr(66) & Chr(77)
' Let's get the file type
s_Type = Me.GetBytes(FilePath, 0, 3)
If s_Type = s_GIF Then
' This is a GIF file
Me.SetImageType = "GIF"
Me.SetWidth = Me.LittleEndian(Me.GetBytes(FilePath, 7, 2))
Me.SetHeight = Me.LittleEndian(Me.GetBytes(FilePath, 9, 2))
Me.SetDepth = 2 ^ ((Asc(Me.GetBytes(FilePath, 11, 1)) And 7) + 1)
ElseIf Left(s_Type, 2) = s_BMP Then
' This is a BMP file
Me.SetImageType = "BMP"
Me.SetWidth = Me.LittleEndian(Me.GetBytes(FilePath, 19, 2))
Me.SetHeight = Me.LittleEndian(Me.GetBytes(FilePath, 23, 2))
Me.SetDepth = 2 ^ (Asc(Me.GetBytes(FilePath, 29, 1)))
ElseIf s_Type = s_PNG Then
' This is a PNG file
Me.SetImageType = "PNG"
Me.SetWidth = Me.BigEndian(Me.GetBytes(FilePath, 19, 2))
Me.SetHeight = Me.BigEndian(Me.GetBytes(FilePath, 23, 2))
s_Depth = Me.GetBytes(FilePath, 25, 2)
Select Case Asc(Right(s_Depth, 1))
Case 0
Me.SetDepth = 2 ^ Asc(Left(s_Depth, 1))
Case 2
Me.SetDepth = 2 ^ (Asc(Left(s_Depth, 1)) * 3)
Case 3
Me.SetDepth = 2 ^ Asc(Left(s_Depth, 1))
Case 4
Me.SetDepth = 2 ^ (Asc(Left(s_Depth, 1)) * 2)
Case 6
Me.SetDepth = 2 ^ (Asc(Left(s_Depth, 1)) * 4)
Case Else
Me.SetDepth = -1
End Select
Else
' We get all the bytes of the file
s_Buffer = Me.GetBytes(FilePath, 0, -1)
BufferSize = Len(s_Buffer)
FlagFound = 0
' We search for a JPEG file
s_Search = Chr(255) & Chr(216) & Chr(255)
FlagFound = InStr(s_Buffer, s_Search)
If FlagFound = 0 Then
Exit Sub
End If
Me.SetImageType = "JPG"
FlagFound = FlagFound + 2
ExitLoop = False
Do While ExitLoop = False And FlagFound < BufferSize
Do While Asc(Mid(s_Buffer, FlagFound, 1)) = 255 And FlagFound < BufferSize
FlagFound = FlagFound + 1
Loop
If Asc(Mid(s_Buffer, FlagFound, 1)) < 192 Or Asc(Mid(s_Buffer, FlagFound, 1)) > 195 Then
FlagFound = FlagFound + Me.BigEndian(Mid(s_Buffer, FlagFound + 1, 2)) + 1
Else
ExitLoop = True
End If
Loop
If ExitLoop = False Then
Me.SetWidth = -1
Me.SetHeight = -1
Me.SetDepth = -1
Else
Me.SetWidth = Me.BigEndian(Mid(s_Buffer, FlagFound + 6, 2))
Me.SetHeight = Me.BigEndian(Mid(s_Buffer, FlagFound + 4, 2))
Me.SetDepth = 2 ^ (Asc(Mid(s_Buffer, FlagFound + 8, 1)) * 8)
End If
End If
End Sub
End Class
%> |
Partager