mirror of https://github.com/wanadev/yoga.git
Update the code to not use deprecated constants on newer Pillow versions
This commit is contained in:
parent
5818d7a984
commit
26635f0bd3
|
@ -56,7 +56,7 @@ Changelog
|
|||
|
||||
* **[NEXT]** (changes on ``master`` that have not been released yet):
|
||||
|
||||
* Nothing yet
|
||||
* Update the code to not use deprecated constants on newer Pillow versions
|
||||
|
||||
* **1.2.1:**
|
||||
|
||||
|
|
|
@ -236,6 +236,15 @@ from .options import normalize_options
|
|||
from . import helpers
|
||||
|
||||
|
||||
# Since Pillow v9.1.0, constants on the Image object are deprecated and will be
|
||||
# removed in Pillow v10.0.0. This code ansure the compatibility with all
|
||||
# versions.
|
||||
# See: https://pillow.readthedocs.io/en/stable/deprecations.html#constants
|
||||
Resampling = Image
|
||||
if hasattr(Image, "Resampling"):
|
||||
Resampling = Image.Resampling
|
||||
|
||||
|
||||
def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
|
||||
"""Optimize given image.
|
||||
|
||||
|
@ -273,7 +282,7 @@ def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
|
|||
|
||||
# Resize image if requested
|
||||
if options["resize"] != "orig":
|
||||
image.thumbnail(options["resize"], Image.LANCZOS)
|
||||
image.thumbnail(options["resize"], Resampling.LANCZOS)
|
||||
|
||||
# Quantize if requested
|
||||
if options["enable_quantization"]:
|
||||
|
|
|
@ -3,16 +3,24 @@ import mozjpeg_lossless_optimization
|
|||
from PIL import Image
|
||||
|
||||
|
||||
# Since Pillow v9.1.0, constants on the Image object are deprecated and will be
|
||||
# removed in Pillow v10.0.0. This code ansure the compatibility with all
|
||||
# versions.
|
||||
# See: https://pillow.readthedocs.io/en/stable/deprecations.html#constants
|
||||
Transpose = Image
|
||||
if hasattr(Image, "Transpose"):
|
||||
Transpose = Image.Transpose
|
||||
|
||||
EXIF_TAG_ORIENTATION = 0x0112
|
||||
ORIENTATION_OPERATIONS = {
|
||||
1: [],
|
||||
2: [Image.FLIP_LEFT_RIGHT],
|
||||
3: [Image.ROTATE_180],
|
||||
4: [Image.FLIP_TOP_BOTTOM],
|
||||
5: [Image.FLIP_LEFT_RIGHT, Image.ROTATE_90],
|
||||
6: [Image.ROTATE_270],
|
||||
7: [Image.FLIP_LEFT_RIGHT, Image.ROTATE_270],
|
||||
8: [Image.ROTATE_90],
|
||||
2: [Transpose.FLIP_LEFT_RIGHT],
|
||||
3: [Transpose.ROTATE_180],
|
||||
4: [Transpose.FLIP_TOP_BOTTOM],
|
||||
5: [Transpose.FLIP_LEFT_RIGHT, Transpose.ROTATE_90],
|
||||
6: [Transpose.ROTATE_270],
|
||||
7: [Transpose.FLIP_LEFT_RIGHT, Transpose.ROTATE_270],
|
||||
8: [Transpose.ROTATE_90],
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue