diff --git a/Tests/test_file_pdf.py b/Tests/test_file_pdf.py index 2b5c12ea3..bb003a32c 100644 --- a/Tests/test_file_pdf.py +++ b/Tests/test_file_pdf.py @@ -67,6 +67,7 @@ class TestFilePdf(PillowTestCase): def test_resolution(self): self.helper_save_as_pdf("RGB", resolution=300.5) self.helper_save_as_pdf("RGB", resolution=(300, 150)) + self.assertRaises(ValueError, self.helper_save_as_pdf, "RGB", resolution=-100) def test_unsupported_mode(self): im = hopper("LA") diff --git a/src/PIL/PdfImagePlugin.py b/src/PIL/PdfImagePlugin.py index 9e01ea692..eea3d9e32 100644 --- a/src/PIL/PdfImagePlugin.py +++ b/src/PIL/PdfImagePlugin.py @@ -63,6 +63,8 @@ def _save(im, fp, filename, save_all=False): else: pdf_width_res = resolution[0] pdf_height_res = resolution[1] + if pdf_width_res <= 0 or pdf_height_res <= 0: + raise ValueError("Resolution must be > 0") info = { "title": None if is_appending else os.path.splitext(