scardine / image_size

Get image width and height given a file path using minimal dependencies (no need for PIL, libjpeg, libpng, etc)
MIT License
153 stars 45 forks source link

TypeError for data won't detect PNG properly #8

Closed KeithTurkowski closed 8 years ago

KeithTurkowski commented 8 years ago

This is related to Issue #7

This can be fixed by changing this line to include the "b" character before 'IHDR'

and (data[12:16] == b'IHDR')):

I believe these lines should also be changed in the same way, but I have NOT TESTED them.

if (size >= 10) and data[:6] in (b'GIF87a', b'GIF89a'): elif (size >= 8) and data[:4] in (b"II\052\000", b"MM\000\052"):

I don't actually get an error message, but it was not detecting the IHDR correctly as a result. Adding the 'b' fixed it and returned proper dimensions.

KeithTurkowski commented 8 years ago
        if (size >= 10) and data[:6] in (b'GIF87a', b'GIF89a'):

        # GIFs

        imgtype = GIF

        w, h = struct.unpack("<HH", data[6:10])

        width = int(w)

        height = int(h)

    elif ((size >= 24) and data.startswith(b'\211PNG\r\n\032\n')

          and (data[12:16] == b'IHDR')):

@scardine

This section also needs to be changed 'b' added before the strings: 'GIF87a', 'GIF89a', and 'IHDR'.

Not sure if this was clear from my previous post.

Thanks!