📄 z_exif.asp
字号:
<%
Const ExifShowMode = 1
Const ExifBoardList = "2,3,11,16"
Const ExifOldUpload = 0
Const DvbbsCrLf = " "
const IFD_IDX_Tag_No = 0
const IFD_IDX_Tag_Name = 1
const IFD_IDX_Data_Format = 2
const IFD_IDX_Components = 3
const IFD_IDX_Value = 4
const IFD_IDX_Value_Desc = 5
const IFD_IDX_OffsetToValue = 6
Class Cls_Exif
Private ExifLookup
Private Offset_to_IFD0
Private Offset_to_APP1
Private Offset_to_TIFF
Private Length_of_APP1
Private Offset_to_Next_IFD
Private IFDDirectory
Private Offset_to_ExifSubIFD
Private ImageFileName
Private IsLoaded
Private ExifTemp
Private Sub Class_Initialize()
set ExifLookup = Server.CreateObject("Scripting.Dictionary")
'IFD0 Tags
ExifLookup.Add "Image Description", "010E"
ExifLookup.Add "Camera Make", "010F"
ExifLookup.Add "Camera Model", "0110"
ExifLookup.Add "Orientation", "0112"
ExifLookup.Add "X Resolution", "011A"
ExifLookup.Add "Y Resolution", "011B"
ExifLookup.Add "Resolution Unit", "0128"
ExifLookup.Add "Software", "0131"
ExifLookup.Add "Date Time", "0132"
ExifLookup.Add "White Point", "013E"
ExifLookup.Add "Primary Chromaticities", "013F"
ExifLookup.Add "YCbCr Coefficients", "0211"
ExifLookup.Add "YCbCr Positioning", "0213"
ExifLookup.Add "Reference Black White", "0214"
ExifLookup.Add "Copyright", "8298"
ExifLookup.Add "Exif Offset", "8769"
'ExifSubIFD Tags
ExifLookup.Add "Exposure Time", "829A"
ExifLookup.Add "FStop", "829D"
ExifLookup.Add "Exposure Program", "8822"
ExifLookup.Add "ISO Speed Ratings", "8827"
ExifLookup.Add "Exif Version", "9000"
ExifLookup.Add "Date Time Original", "9003"
ExifLookup.Add "Date Time Digitized", "9004"
ExifLookup.Add "Components Configuration", "9101"
ExifLookup.Add "Compressed Bits Per Pixel", "9102"
ExifLookup.Add "Shutter Speed Value", "9201"
ExifLookup.Add "Aperture Value", "9202"
ExifLookup.Add "Brightness Value", "9203"
ExifLookup.Add "Exposure Bias Value", "9204"
ExifLookup.Add "Max Aperture Value", "9205"
ExifLookup.Add "Subject Distance", "9206"
ExifLookup.Add "Metering Mode", "9207"
ExifLookup.Add "Light Source", "9208"
ExifLookup.Add "Flash", "9209"
ExifLookup.Add "Focal Length", "920A"
ExifLookup.Add "Maker Note", "927C"
ExifLookup.Add "User Comment", "9286"
ExifLookup.Add "Subsec Time", "9290"
ExifLookup.Add "Subsec Time Original", "9291"
ExifLookup.Add "Subsec Time Digitized", "9292"
ExifLookup.Add "Flash Pix Version", "A000"
ExifLookup.Add "Color Space", "A001"
ExifLookup.Add "Exif Image Width", "A002"
ExifLookup.Add "Exif Image Height", "A003"
ExifLookup.Add "Related Sound File", "A004"
ExifLookup.Add "Exif Interoperability Offset", "A005"
ExifLookup.Add "Focal Plane X Resolution", "A20E"
ExifLookup.Add "Focal Plane Y Resolution", "A20F"
ExifLookup.Add "Focal Plane Resolution Unit", "A210"
ExifLookup.Add "Exposure Index", "A215"
ExifLookup.Add "Sensing Method", "A217"
ExifLookup.Add "File Source", "A300"
ExifLookup.Add "Scene Type", "A301"
ExifLookup.Add "CFA Pattern", "A302"
'Interoperability IFD Tags
ExifLookup.Add "Interoperability Index", "01"
ExifLookup.Add "Interoperability Version", "02"
ExifLookup.Add "Related Image File Format", "1000"
ExifLookup.Add "Related Image Width", "1001"
ExifLookup.Add "Related Image Length", "1002"
'IFD1 Tags
ExifLookup.Add "Image Width", "0100"
ExifLookup.Add "Image Height", "0101"
ExifLookup.Add "Bits Per Sample", "0102"
ExifLookup.Add "Compression", "0103"
ExifLookup.Add "Photometric Interpretation", "0106"
ExifLookup.Add "Strip Offsets", "0111"
ExifLookup.Add "Sample Per Pixel", "0115"
ExifLookup.Add "Rows Per Strip", "0116"
ExifLookup.Add "Strip Byte Counts", "0117"
ExifLookup.Add "X Resolution 2", "011A"
ExifLookup.Add "Y Resolution 2", "011B"
ExifLookup.Add "Planar Configuration", "011C"
ExifLookup.Add "Resolution Unit 2", "0128"
ExifLookup.Add "JPEG Interchange Format", "0201"
ExifLookup.Add "JPEG Interchange Format Length", "0202"
ExifLookup.Add "YCbCr Coeffecients", "0211"
ExifLookup.Add "YCbCr Sub Sampling", "0212"
ExifLookup.Add "YCbCr Positioning 2", "0213"
ExifLookup.Add "Reference Black White 2", "0214"
'Misc Tags
ExifLookup.Add "New Subfile Type", "FE"
ExifLookup.Add "Subfile Type", "FF"
ExifLookup.Add "Transfer Function", "012D"
ExifLookup.Add "Artist", "013B"
ExifLookup.Add "Predictor", "013D"
ExifLookup.Add "Tile Width", "0142"
ExifLookup.Add "Tile Length", "0143"
ExifLookup.Add "Tile Offsets", "0144"
ExifLookup.Add "Tile Byte Counts", "0145"
ExifLookup.Add "Sub IFDs", "014A"
ExifLookup.Add "JPEG Tables", "015B"
ExifLookup.Add "CFA Repeat Pattern Dim", "828D"
ExifLookup.Add "CFA Pattern 2", "828E"
ExifLookup.Add "Battery Level", "828F"
ExifLookup.Add "IPTC_NAA", "83BB"
ExifLookup.Add "Inter Color Profile", "8773"
ExifLookup.Add "Spectral Sensitivity", "8824"
ExifLookup.Add "GPS Info", "8825"
ExifLookup.Add "OECF", "8828"
ExifLookup.Add "Interlace", "8829"
ExifLookup.Add "Time Zone Offset", "882A"
ExifLookup.Add "Self Timer Mode", "882B"
ExifLookup.Add "Flash Energy", "920B"
ExifLookup.Add "Spatial Frequency Response", "920C"
ExifLookup.Add "Noise", "920D"
ExifLookup.Add "Image Number", "9211"
ExifLookup.Add "Security Classification", "9212"
ExifLookup.Add "Image History", "9213"
ExifLookup.Add "Subject Location", "9214"
ExifLookup.Add "Exposure Index 2", "9215"
ExifLookup.Add "TIFFEP Standard ID", "9216"
ExifLookup.Add "Flash Energy 2", "A20B"
ExifLookup.Add "Spatial Frequency Response 2", "A20C"
ExifLookup.Add "Subject Location 2", "A214"
ExifTemp=array(0)
IFDDirectory = array(0)
End Sub
Private Sub class_terminate()
End Sub
Public Property Let ImageFile(ByVal vNewValue)
ImageFileName = vNewValue
LoadImage ImageFileName
End Property
Public Property Get ImageFile()
ImageFile=ImageFileName
End Property
Public Function LookupExifTag(which)
dim item
for each item in ExifLookup
if ExifLookup(item) = which then
LookupExifTag = item
exit function
end if
next
LookupExifTag = which
End Function
Public Function hasExifInfo()
If IsLoaded = False Or ImageFileName = "" Then
hasExifInfo = False
ElseIf UBound(IFDDirectory)<1 Then
hasExifInfo = False
Else
hasExifInfo = True
End If
End Function
Public Function GetExifByName(ExifTag)
Dim i
If IsLoaded = False And ImageFileName <> "" Then
LoadImage (ImageFileName)
ElseIf IsLoaded = False And ImageFileName = "" Then
Exit Function
End If
For i = 0 To UBound(IFDDirectory) - 1
If IFDDirectory(i)(IFD_IDX_Tag_Name) = ExifTag Then
if IFDDirectory(i)(IFD_IDX_Value_Desc) <> "" then
GetExifByName = IFDDirectory(i)(IFD_IDX_Value_Desc)
else
GetExifByName = IFDDirectory(i)(IFD_IDX_Value)
End if
Exit For
End If
Next
End Function
Private sub LoadImage(picFile)
If ImageFileName = "" Then
ImageFileName = picFile
If ImageFileName = "" Then
Exit sub
End If
End If
OpenJPGFile ImageFileName
If InspectJPGFile = False Then
IsLoaded = False
Exit Sub
End If
If IsIntel Then
Offset_to_IFD0 = ByteToLong(ExifTemp(Offset_to_APP1 + 17), ExifTemp(Offset_to_APP1 + 16), ExifTemp(Offset_to_APP1 + 15), ExifTemp(Offset_to_APP1 + 14))
Else
Offset_to_IFD0 = ByteToLong(ExifTemp(Offset_to_APP1 + 14), ExifTemp(Offset_to_APP1 + 15), ExifTemp(Offset_to_APP1 + 16), ExifTemp(Offset_to_APP1 + 17))
End If
IsLoaded = True
GetDirectoryEntries Offset_to_TIFF + Offset_to_IFD0
MakeSenseOfMeaninglessValues
End sub
Private Function InspectJPGFile()
Dim i
if UBound(ExifTemp)<=0 then
InspectJPGFile = False
Exit Function
end if
If ExifTemp(0) <> &HFF And ExifTemp(1) <> &HD8 Then
InspectJPGFile = False
Else
For i = 2 To UBound(ExifTemp) - 1
If ExifTemp(i) = &HFF And ExifTemp(i + 1) = &HE1 Then
Offset_to_APP1 = i
Exit For
End If
Next
If Offset_to_APP1 = 0 Then
InspectJPGFile = False
End If
Offset_to_TIFF = Offset_to_APP1 + 10
Length_of_APP1 = ByteToInt(ExifTemp(Offset_to_APP1 + 2), ExifTemp(Offset_to_APP1 + 3))
If Not (ExifTemp(Offset_to_APP1 + 4) = ASC("E") And ExifTemp(Offset_to_APP1 + 5) = ASC("x") And ExifTemp(Offset_to_APP1 + 6) = ASC("i") And ExifTemp(Offset_to_APP1 + 7) = ASC("f")) Then
InspectJPGFile = False
Exit Function
End If
InspectJPGFile = True
End If
End Function
Private Function IsIntel()
If ExifTemp(Offset_to_TIFF) = &H49 Then
IsIntel = True
Else
IsIntel = False
End If
End Function
Private Function OpenJPGFile(FileName)
const TristateUseDefault = -2
const TristateTrue = -1
const TristateFalse = 0
const ForReading = 1
const ForWriting = 2
const ForAppending = 8
Dim Ascii, LastByte, CurByte, SOSFound
Dim FSO, File, i
If Not FileName = "" Then
If InStr(1, FileName, ":\") = 0 Then
FileName = Server.MapPath(FileName)
End If
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(FileName) Then
Set File = Server.CreateObject("ADODB.Stream")
File.Type = 1
File.Mode = 3
File.Open
File.LoadFromFile FileName
i = 0
While Not File.EOS and SOSFound = false
Ascii = ascb(File.Read(1))
LastByte = CurByte
CurByte = Ascii
if (LastByte = &HFF and CurByte = &HDA) or i > 100000 then
SOSFound = true
end if
ExifTemp(i) = CurByte
i = i + 1
ReDim Preserve ExifTemp(i)
Wend
File.Close
Set File = Nothing
End If
Set FSO = Nothing
End If
end function
Private Sub GetDirectoryEntries(Offset)
const ExifOffset = "8769"
const MakerNote = "927C"
const m_BYTE = 1
const m_STRING = 2
const m_SHORT = 3
const m_LONG = 4
const m_RATIONAL = 5
const m_SBYTE = 6
const m_UNDEFINED = 7
const m_SSHORT = 8
const m_SLONG = 9
const m_SRATIONAL = 10
const m_SINGLE = 11
const m_DOUBLE = 12
Dim No_of_Entries
Dim Upper_IFDDirectory
Dim NewDimensions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -