iter(dict) is equivalent to iter(dict.keys()), so simply act on the dict
instead of adding the extra call.
Inspired by Lennart Regebro's PyCon 2017 presentation "Prehistoric
Patterns in Python". Available at:
https://www.youtube.com/watch?v=V5-JH23Vk0I
* DPI is a tuple
* Some EXIF only contains an X resolution for DPI
* Refactor
* Test with no DPI in EXIF
* Handle EXIF with no DPI
* Created with: exiftool "-*resolution*"= photoshop-200dpi.jpg
* Test when not in EXIF, DPI==72,72
* Use X resolution for Y, default to 72,72 dpi
* Created with: exiftool -exif:ResolutionUnit=cm photoshop-200dpi.jpg
* Test for EXIF with dpcm instead of dpi
* Convert dpcm to dpi, and default to inches if unit unknown
When saving a JPEG and specifying 'keep' for quality or subsampling,
if the source JPEG image is in grayscale mode, don't try to find the
subsampling of the source, because grayscale images don't have any
subsampling (it's only for color components).
For the moment the fix also ignores subsampling of CMYK JPEG because
currently Pillow doesn't support encoding JPEG in YCCK mode (and
subsampling doesn't make sense in CMYK, but Pillow permits saving CMYK
JPEG with subsampling, that's a bug). This fix pass those errors
silently, i.e. it doesn't raise an error when 'keep' is used but it's
not possible to keep the subsampling (because the image is grayscale
or CMYK). I think it's the proper behavior but I'm not sure.
value (in dictionary format).
Previously, this would throw a TypeError when checking if the qtables
value was actually a preset. By adding an isStringType check, we can
avoid this error.
when the jpeg encoder sees the flags optimize or progressive (or progression)
it will write the full image in one shot.
The bufsize needs to be big enough to hold the entire image. The current heuristic
is that the entire compressed image will fit in width * height bytes, but this
heuristic is only applied to save operations with the flag "optimize" and not to
save operations with the flag "progressive".
This patch fixes this oversight.
(Btw, it will probably be a good idea to have a loop that retries with a bigger
bufsize in case this guess is not big enough.)
Most of the differences are in tobytes/tostring naming and expected
behavior of the bytes() constructor. The latter was usually easy to fix
with the right bytes literal.
This is a good preview of what will have to happen in the Python 3 code.
This is Christoph Gohlke's test suite from his personal PIL package found
at http://www.lfd.uci.edu/~gohlke/pythonlibs/.
This is just to bring it in as a separate commit. Future commits will align
it with Pillow.