Fix Pillow deprecation warnings
This commit is contained in:
@@ -24,6 +24,15 @@ from ocrmypdf.exceptions import MissingDependencyError, SubprocessOutputError
|
||||
from ocrmypdf.helpers import Resolution
|
||||
from ocrmypdf.subprocess import get_version, run, run_polling_stderr
|
||||
|
||||
try:
|
||||
ROTATE_90 = Image.Transpose.ROTATE_90
|
||||
ROTATE_180 = Image.Transpose.ROTATE_180
|
||||
ROTATE_270 = Image.Transpose.ROTATE_270
|
||||
except AttributeError:
|
||||
ROTATE_90 = Image.ROTATE_90
|
||||
ROTATE_180 = Image.ROTATE_180
|
||||
ROTATE_270 = Image.ROTATE_270
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
missing_gs_error = """
|
||||
@@ -132,11 +141,11 @@ def rasterize_pdf(
|
||||
# rotation is a clockwise angle and Image.ROTATE_* is
|
||||
# counterclockwise so this cancels out the rotation
|
||||
if rotation == 90:
|
||||
im = im.transpose(Image.ROTATE_90)
|
||||
im = im.transpose(ROTATE_90)
|
||||
elif rotation == 180:
|
||||
im = im.transpose(Image.ROTATE_180)
|
||||
im = im.transpose(ROTATE_180)
|
||||
elif rotation == 270:
|
||||
im = im.transpose(Image.ROTATE_270)
|
||||
im = im.transpose(ROTATE_270)
|
||||
if rotation % 180 == 90:
|
||||
page_dpi = page_dpi.flip_axis()
|
||||
im.save(fspath(output_file), dpi=page_dpi)
|
||||
|
||||
@@ -38,6 +38,11 @@ from ocrmypdf.optimize import optimize
|
||||
from ocrmypdf.pdfa import generate_pdfa_ps
|
||||
from ocrmypdf.pdfinfo import Colorspace, Encoding, PdfInfo
|
||||
|
||||
try:
|
||||
BICUBIC = Image.Resampling.BICUBIC
|
||||
except AttributeError:
|
||||
BICUBIC = Image.BICUBIC
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
VECTOR_PAGE_DPI = 400
|
||||
@@ -484,7 +489,7 @@ def preprocess_deskew(input_file: Path, page_context: PageContext):
|
||||
# According to Pillow docs, .rotate() will automatically use Image.NEAREST
|
||||
# resampling if image is mode '1' or 'P'
|
||||
deskewed = im.rotate(
|
||||
deskew_angle_degrees, resample=Image.BICUBIC, fillcolor='white'
|
||||
deskew_angle_degrees, resample=BICUBIC, fillcolor='white'
|
||||
)
|
||||
deskewed.save(output_file, dpi=dpi)
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ def test_xml_metadata_preserved(test_file, output_type, resources, outpdf):
|
||||
try:
|
||||
from libxmp.utils import file_to_dict # pylint: disable=import-outside-toplevel
|
||||
except Exception: # pylint: disable=broad-except
|
||||
pytest.skip("libxmp not available or libexempi3 not installed")
|
||||
pytest.skip(reason="libxmp not available or libexempi3 not installed")
|
||||
|
||||
before = file_to_dict(str(input_file))
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ def test_stdin(ocrmypdf_exec, resources, outpdf):
|
||||
|
||||
def test_stdout(ocrmypdf_exec, resources, outpdf):
|
||||
if 'COV_CORE_DATAFILE' in os.environ:
|
||||
pytest.skip(msg="Coverage uses stdout")
|
||||
pytest.skip(reason="Coverage uses stdout")
|
||||
|
||||
input_file = str(resources / 'francais.pdf')
|
||||
output_file = str(outpdf)
|
||||
@@ -72,7 +72,7 @@ def test_bad_locale(monkeypatch):
|
||||
)
|
||||
def test_dev_null(resources):
|
||||
if 'COV_CORE_DATAFILE' in os.environ:
|
||||
pytest.skip(msg="Coverage uses stdout")
|
||||
pytest.skip(reason="Coverage uses stdout")
|
||||
|
||||
p = run_ocrmypdf(
|
||||
resources / 'trivial.pdf',
|
||||
|
||||
Reference in New Issue
Block a user