Skip to content

Commit

Permalink
always convert JPEG/RGBA to JPEG/RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Aug 11, 2022
1 parent a6cef67 commit 58aa126
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion avatar/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AvatarConf(AppConf):
MAX_SIZE = 1024 * 1024
THUMB_FORMAT = "PNG"
THUMB_QUALITY = 85
THUMB_MODES = ["RGB", "RGBA"]
THUMB_MODES = ("RGB", "RGBA")
HASH_FILENAMES = False
HASH_USERDIRNAMES = False
EXPOSE_USERNAMES = False
Expand Down
4 changes: 3 additions & 1 deletion avatar/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ def create_thumbnail(self, size, quality=None):
else:
diff = int((h - w) / 2)
image = image.crop((0, diff, w, h - diff))
if image.mode not in (settings.AVATAR_THUMB_MODES):
if settings.AVATAR_THUMB_FORMAT == "JPEG" and image.mode == "RGBA":
image = image.convert("RGB")
elif image.mode not in (settings.AVATAR_THUMB_MODES):
image = image.convert(settings.AVATAR_THUMB_MODES[0])
image = image.resize((size, size), settings.AVATAR_RESIZE_METHOD)
thumb = BytesIO()
Expand Down
6 changes: 2 additions & 4 deletions docs/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,9 @@ appear on the site. Listed below are those settings:
"keep" (only JPEG) as provided by Pillow. Defaults to `85`.

.. py:data:: AVATAR_THUMB_MODES
A list of acceptable modes for thumbnails as provided by Pillow. If the mode
A sequence of acceptable modes for thumbnails as provided by Pillow. If the mode
of the image is not in the list, the thumbnail will be converted to the
first mode in the list. Note that you need to set this to modes available
for AVATAR_THUMB_FORMAT and JPEG does not support RGBA. Defaults to
`['RGB', 'RGBA']`.
first mode in the list. Defaults to `('RGB', 'RGBA')`.

.. py:data:: AVATAR_CLEANUP_DELETED

Expand Down

0 comments on commit 58aa126

Please sign in to comment.