set GifImagePlugin.LOADING_STRATEGY to RGB_AFTER_DIFFERENT_PALETTE_ONLY in Pillow >= 9.1.0 (closes: )

This commit is contained in:
Johannes Schauer Marin Rodrigues 2022-04-07 21:57:37 +02:00
parent 1d52530229
commit d9345ac767
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -22,7 +22,17 @@ import sys
import os import os
import zlib import zlib
import argparse import argparse
from PIL import Image, TiffImagePlugin from PIL import Image, TiffImagePlugin, GifImagePlugin
if hasattr(GifImagePlugin, "LoadingStrategy"):
# Pillow 9.0.0 started emitting all frames but the first as RGB instead of
# P to make sure that more than 256 colors can be represented. But palette
# images compress far better than RGB images in PDF so we instruct Pillow
# to only emit RGB frames if the palette differs and return P otherwise.
# This works since Pillow 9.1.0.
GifImagePlugin.LOADING_STRATEGY = (
GifImagePlugin.LoadingStrategy.RGB_AFTER_DIFFERENT_PALETTE_ONLY
)
# TiffImagePlugin.DEBUG = True # TiffImagePlugin.DEBUG = True
from PIL.ExifTags import TAGS from PIL.ExifTags import TAGS