Tip: Reading the image dimensions of a GIF file 
Author Message
 Tip: Reading the image dimensions of a GIF file

This question popped up several times, in the last weeks alone. I found
a solution in the meantime. It's so easy, you wouldn't believe it.

A GIF file is a pretty complicated thing. It can consist of several
images (in the case of an animated GIF), that need not even be all the
same size. However, there is the notion of a virtual screen on which all
images are painted. The image dimensions, as most people would think of
it, is precisely the dimensions of this screen.

These dimensions are stored right at the beginning of the GIF file,
right after a 6 byte signature (that marks it as a GIF file), as a
couple of 2-byte unsigned integers, in low-endian (Intel) order.

So getting the image dimensions out of a GIF file can be really dead
simple. This code will actually do just that (although, in practice, you
probably won't want the messagebox):

  Type GIFheader
    signature As String * 3
    version As String * 3
    width As Integer
    height As Integer
  End Type

  Function GIFdimensions$ (ByVal filePath$)
    Dim handle%: handle = FreeFile
    Dim GIFheader As GIFheader
    Open filePath For Binary Access Read As #handle
    Get #handle, , GIFheader
    Close #handle
    If GIFheader.signature = "GIF" And _
      (GIFheader.version = "87a" Or GIFheader.version = "89a") Then
        GIFdimensions = CStr(GIFheader.width) & " x " _
          & CStr(GIFheader.height)
        MsgBox "Not a GIF file",48,"ERROR"
    End If
  End Function


Mon, 02 Oct 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Dimensions of GIF and JPG from files

2. Dimensions of GIF and JPG from files

3. File dimensions TIF images

4. Getting Dimension of an image file

5. Reading a GIF image from a Web server using Winsock control

6. .bmp, .gif, .jpg dimensions

7. ? How to get dimensions of gif or jpg

8. Dimensions on gif / jpg

9. Save to GIF file from resource GIF file

10. Create a GIF (image file) from VB

11. GIF image in resource files ? VB6

12. Displaying .gif files in an image control


Powered by phpBB® Forum Software