Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waikato-datamining/python-image-complete
Python 3 library for checking whether an image is complete or not (looking for EOF markers or checking file length).
https://github.com/waikato-datamining/python-image-complete
imaging python3
Last synced: about 2 months ago
JSON representation
Python 3 library for checking whether an image is complete or not (looking for EOF markers or checking file length).
- Host: GitHub
- URL: https://github.com/waikato-datamining/python-image-complete
- Owner: waikato-datamining
- License: mit
- Created: 2019-04-16T22:30:28.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T04:55:40.000Z (8 months ago)
- Last Synced: 2024-09-26T03:38:52.372Z (3 months ago)
- Topics: imaging, python3
- Language: Python
- Homepage:
- Size: 51.8 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
# 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
* BMP (checks file length)
* https://en.wikipedia.org/wiki/BMP_file_format#File_structure
* GIF (checks EOF marker)
* https://en.wikipedia.org/wiki/GIF#File_format
* JPG (checks EOF marker)
* http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure
* PNG (checks EOF marker)
* https://en.wikipedia.org/wiki/Portable_Network_Graphics#Critical_chunks
* http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html#Chunk-layout
* http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.IEND* WebP (compares data length after RIFF header with file length)
* https://developers.google.com/speed/webp/docs/riff_container
## Examples### Auto detection
```python
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
```python
from image_complete.jpg import is_jpg_complete, is_jpgf = "/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)
```python
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))
```