Skip to content

Commit

Permalink
Conversion of GIF/PNG to JPEG
Browse files Browse the repository at this point in the history
  • Loading branch information
saschwarz authored and agschwender committed Oct 22, 2017
1 parent 28f75b4 commit 9c9b714
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pilbox/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 9c9b714

Please sign in to comment.