Show error for negative PDF res.

This commit is contained in:
Zheng Jie Tan 2019-04-09 22:01:58 -04:00
parent eacdb3d843
commit aba3e62968
2 changed files with 3 additions and 0 deletions

View File

@ -67,6 +67,7 @@ class TestFilePdf(PillowTestCase):
def test_resolution(self): def test_resolution(self):
self.helper_save_as_pdf("RGB", resolution=300.5) self.helper_save_as_pdf("RGB", resolution=300.5)
self.helper_save_as_pdf("RGB", resolution=(300, 150)) 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): def test_unsupported_mode(self):
im = hopper("LA") im = hopper("LA")

View File

@ -63,6 +63,8 @@ def _save(im, fp, filename, save_all=False):
else: else:
pdf_width_res = resolution[0] pdf_width_res = resolution[0]
pdf_height_res = resolution[1] pdf_height_res = resolution[1]
if pdf_width_res <= 0 or pdf_height_res <= 0:
raise ValueError("Resolution must be > 0")
info = { info = {
"title": None if is_appending else os.path.splitext( "title": None if is_appending else os.path.splitext(