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 be 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.
pip install python_image_complete
- BMP (extension: .bmp)
- GIF (extension: .gif)
- JPG (extension: .jpg, .jpeg)
- PNG (extension: .png)
- WebP (extension: .webp)
-
BMP (checks file length)
-
GIF (checks EOF marker)
-
JPG (checks EOF marker)
-
PNG (checks EOF marker)
-
WebP (compares data length after RIFF header with file length)
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))
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!")
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))