From 9c9b7148f7fb0dfb8060d2a57f344723efe5542c Mon Sep 17 00:00:00 2001 From: Steve Schwarz Date: Mon, 16 Oct 2017 15:55:47 -0500 Subject: [PATCH] Conversion of GIF/PNG to JPEG --- pilbox/image.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pilbox/image.py b/pilbox/image.py index c23ff54..bb23846 100644 --- a/pilbox/image.py +++ b/pilbox/image.py @@ -277,6 +277,12 @@ def save(self, **kwargs): if opts["quality"] == "keep": save_kwargs["quality"] = "keep" + if fmt == "JPEG" and self.img.mode == 'P': + # Converting old GIF and PNG files to JPEG can raise + # IOError: cannot write mode P as JPEG + # https://mail.python.org/pipermail/python-list/2000-May/036017.html + self.img = self.img.convert("RGB") + try: self.img.save(outfile, fmt, **save_kwargs) except IOError as e: