Skip to content

Python 3 library for checking whether an image is complete or not (looking for EOF markers or checking file length).

License

Notifications You must be signed in to change notification settings

waikato-datamining/python-image-complete

Repository files navigation

python-image-complete

Python 3 library for checking whether an image is complete or not. It is either looking for EOF markers or checking the length of the file against one stored in the file.

Can also operate on bytes or BytesIO objects.

By default, the library operates in strict mode, i.e., no trailing junk data is tolerated. However, by supplying the parameters strict and check_size this can turned into lenient mode. The parameter check_size (i.e., the number of bytes to read from the end of the file) is only used for formats gif, jpg, png.

Supported image formats

  • BMP (extension: .bmp)
  • GIF (extension: .gif)
  • JPG (extension: .jpg, .jpeg)
  • PNG (extension: .png)
  • WebP (extension: .webp)

File structures

Examples

Auto detection

from image_complete.auto import is_image_complete

# using file names
print(is_image_complete("/some/where/hello_world.jpg"))
print(is_image_complete("/some/where/image.png"))

# using bytes or BytesIO
with open("/some/where/image.bmp", "rb") as fp:
    b = fp.read()
print(is_image_complete(b))

JPG specific

from image_complete.jpg import is_jpg_complete, is_jpg

f = "/some/where/hello_world.jpg"
if is_jpg(f):
    print(is_jpg_complete(f))
else:
    print("Not a JPG!")

Lenient mode (i.e., tolerating trailing junk data)

from image_complete.auto import is_image_complete

# using file names
print(is_image_complete("/some/where/hello_world.jpg", strict=False, check_size=100))
print(is_image_complete("/some/where/image.png", strict=False, check_size=100))

# using bytes or BytesIO
with open("/some/where/image.bmp", "rb") as fp:
    b = fp.read()
print(is_image_complete(b, strict=False))

About

Python 3 library for checking whether an image is complete or not (looking for EOF markers or checking file length).

Topics

Resources

License

Stars

Watchers

Forks

Languages