Use FSO to get picture file information (size, width, height)

Source: Internet
Author: User
Tags chr numeric value
FSO <%
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: BMP, GIF, JPG and PNG:::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
''::: :::
':: This function gets a specified number of bytes from::
'::: File, starting at the offset (base 1):::
''::: :::
'::: Passed::::
'::: flnm => filespec of file to read::
'::: Offset => offset at which to start reading:::
'::: bytes => How many bytes to read::
''::: :::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function GetBytes (flnm, offset, bytes)
Dim objFSO
Dim objftemp
Dim objTextStream
Dim lngsize
On Error Resume Next
Set objFSO = CreateObject ("Scripting.FileSystemObject")

' The FileSize
Set objftemp = Objfso.getfile (FLNM)
Lngsize = Objftemp.size
Set objftemp = Nothing
fsoforreading = 1
Set objTextStream = objFSO.OpenTextFile (flnm, fsoforreading)
If offset > 0 Then
Strbuff = Objtextstream.read (offset-1)
End If
If bytes =-1 Then ' Get all!
GetBytes = Objtextstream.read (lngsize) ' ReadAll
Else
GetBytes = Objtextstream.read (bytes)
End If
Objtextstream.close
Set objTextStream = Nothing
Set objFSO = Nothing
End Function
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
''::: :::
'::: Functions to convert two bytes to a numeric value (long)::
'::: (both Little-endian and Big-endian):::
''::: :::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function Lngconvert (strtemp)
Lngconvert = CLng (ASC (Left (strtemp, 1)) + ((ASC (Right (strtemp, 1) * 256))
End Function
function LngConvert2 (strtemp)
LngConvert2 = CLng (ASC (Right (strtemp, 1)) + ((ASC (Left (strtemp, 1)) * 256))
End Function

'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
''::: :::
'::: This function does most to the real work. It would attempt:::
'::: To read any file, regardless of the extension, and would:::
'::: Identify if it is a graphical image. :::
''::: :::
'::: Passed::::
'::: flnm => filespec of file to read::
'::: Width => width of Image:::
'::: Height => height of Image:::
'::: Depth => color depth (in number of colors):::
'::: strimagetype=> type of image (e.g. GIF, BMP, etc.):::
''::: :::
'':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
function Gfxspex (flnm, width, height, depth, strimagetype)
Dim strpng
Dim strgif
Dim strbmp
Dim strtype
Strtype = ""
Strimagetype = "(unknown)"
Gfxspex = False
Strpng = Chr (137) & Chr (+) & Chr (78)
Strgif = "GIF"
Strbmp = Chr ($) & Chr (77)
Strtype = GetBytes (flnm, 0, 3)
If strtype = Strgif Then ' is GIF
Strimagetype = "GIF"
Width = Lngconvert (GetBytes (FLNM, 7, 2))
Height = Lngconvert (GetBytes (FLNM, 9, 2))
Depth = 2 ^ ((ASC (GetBytes (FLNM, 1)) and 7) + 1)
Gfxspex = True
ElseIf Left (strtype, 2) = Strbmp then "is BMP
Strimagetype = "BMP"
Width = Lngconvert (GetBytes (FLNM, 19, 2))
Height = Lngconvert (GetBytes (FLNM, 23, 2))
Depth = 2 ^ (ASC (GetBytes (FLNM, 29, 1))
Gfxspex = True
ElseIf strtype = Strpng Then ' is PNG
Strimagetype = "PNG"
Width = LngConvert2 (GetBytes (FLNM, 19, 2))
Height = LngConvert2 (GetBytes (FLNM, 23, 2))
Depth = GetBytes (FLNM, 25, 2)
Select Case ASC (Right (depth,1))
Case 0
Depth = 2 ^ (ASC (Left (Depth, 1))
Gfxspex = True
Case 2
Depth = 2 ^ (ASC (Left (Depth, 1)) * 3)
Gfxspex = True
Case 3
Depth = 2 ^ (ASC (Left (Depth, 1))) ' 8
Gfxspex = True
Case 4
Depth = 2 ^ (ASC (Left (Depth, 1)) * 2)
Gfxspex = True
Case 6
Depth = 2 ^ (ASC (Left (Depth, 1)) * 4)
Gfxspex = True
Case Else
Depth =-1
End Select



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.