Skip to content

Instantly share code, notes, and snippets.

View bitsgalore's full-sized avatar

Johan van der Knijff bitsgalore

View GitHub Profile
def get_jpg_quality(pim: 'PIL.Image.Image') -> int:
"""
Implement quality computation following ImageMagick heuristic algorithm:
https://github.com/ImageMagick/ImageMagick/blob/7.1.0-57/coders/jpeg.c#L782
Usage:
```
pim = Img.open(...)
quality = get_jpg_quality(pim)
```
See also https://stackoverflow.com/questions/4354543/