|
Calculate height and width of GIF/JPG files(6) AfterError: retVal(Lbound(retVal)) = w retVal(Ubound(retVal)) = h Close #f ImageSize = retVal End Function
Here's a sample GIFFile class cloning ImageSize() routine original logic:
Private Const GIF_HEADER_LENGTH = 10 Private Const GIF_MARKER = "GIF" Private Const GIF_ID1 = "87a" Private Const GIF_ID2= "89a"
Private Class GIFFile
Private m_w As Integer Private m_h As Integer
Public Property Set fileName As String Dim h ' GIF file Header: "GIF87a" or GIF89a" followed by logical width & height h = Me.Header ' Let's check GIF format presence.. If ( Left$( h, 3 ) <> GIF_MARKER ) Then Error 1000, _ Not a GIF file: Graphical Interchange File "GIF" marker not found If ( Mid$( h, 4, 3 ) <> GIF_ID1 And Mid$( h, 4, 3 ) <> GIF_ID2 ) Then Error 1002, _ Not a GIF file: Graphical Interchange File "87a/89a" identifier not found m_w = Asc( Mid( h, 8, 1 ) ) * 256 + Asc( Mid( h, 7, 1 ) ) ' Little-endian Screen Width m_h = Asc( Mid( h, 10, 1 ) ) * 256 + Asc( Mid( h, 9, 1 ) ) ' Little-endian Screen Height End Property Private Property Get Header As Variant Dim h As Integer h% = Freefile() Open Me.Name For Input Shared As #h Header = Input( GIF_HEADER_LENGTH, #h ) Close #h End Property Public Property Get Heigth As Integer Heigth = m_h End Property Public Property Get Width As Integer Me.Width = m_w End Property
Public Sub new( fileName As String ) Me.FileName = fileName End Sub
End Class
I have added GIF format additional checks intended to detect files holding inaccurate extension/type
|