Skip to content

Commit

Permalink
make PNG default thumbnail format, based on discussion in #180
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Aug 10, 2022
1 parent dca3143 commit ab7e9c6
Show file tree
Hide file tree
Showing 5 changed files with 15 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 @@ -15,7 +15,7 @@ class AvatarConf(AppConf):
DEFAULT_URL = "avatar/img/default.jpg"
MAX_AVATARS_PER_USER = 42
MAX_SIZE = 1024 * 1024
THUMB_FORMAT = "JPEG"
THUMB_FORMAT = "PNG"
THUMB_QUALITY = 85
HASH_FILENAMES = False
HASH_USERDIRNAMES = False
Expand Down
12 changes: 10 additions & 2 deletions docs/index.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,22 @@ appear on the site. Listed below are those settings:
.. py:data:: AVATAR_RESIZE_METHOD

The method to use when resizing images, based on the options available in
PIL. Defaults to ``Image.ANTIALIAS``.
Pillow. Defaults to ``Image.ANTIALIAS``.

.. py:data:: AVATAR_STORAGE_DIR

The directory under ``MEDIA_ROOT`` to store the images. If using a
non-filesystem storage device, this will simply be appended to the beginning
of the file name. Defaults to ``avatars``.
PIL. Defaults to ``Image.ANTIALIAS``.
Pillow. Defaults to ``Image.ANTIALIAS``.

.. py:data:: AVATAR_THUMB_FORMAT
The file format of thumbnails, based on the options available in
Pillow. Defaults to `PNG`.

.. py:data:: AVATAR_THUMB_QUALITY
The quality of thumbnails, between 0 (worst) to 95 (best) or the string
"keep" (only JPEG) as provided by Pillow. Defaults to `85`.

.. py:data:: AVATAR_CLEANUP_DELETED

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def find_version(*file_paths):
],
},
install_requires=[
"Pillow>=2.0",
"django-appconf>=0.6",
"Pillow>=9.2.0",
"django-appconf>=1.0.5",
],
zip_safe=False,
)
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
]
},
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ def test_too_many_avatars(self):
self.assertNotEqual(response.context["upload_avatar_form"].errors, {})
self.assertEqual(count_before, count_after)

@override_settings(AVATAR_THUMB_FORMAT="png")
def test_automatic_thumbnail_creation_RGBA(self):
upload_helper(self, "django.png")
avatar = get_primary_avatar(self.user)
Expand All @@ -228,6 +227,7 @@ def test_automatic_thumbnail_creation_RGBA(self):
)
self.assertEqual(image.mode, "RGBA")

@override_settings(AVATAR_THUMB_FORMAT="JPEG")
def test_automatic_thumbnail_creation_CMYK(self):
upload_helper(self, "django_pony_cmyk.jpg")
avatar = get_primary_avatar(self.user)
Expand Down

0 comments on commit ab7e9c6

Please sign in to comment.