make PNG default thumbnail format, based on discussion in #180

This commit is contained in:
Johannes Wilm 2022-08-10 18:46:09 +02:00
parent dca3143ec2
commit ab7e9c687e
5 changed files with 15 additions and 6 deletions

View file

@ -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

View file

@ -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

View file

@ -58,8 +58,8 @@ setup(
],
},
install_requires=[
"Pillow>=2.0",
"django-appconf>=0.6",
"Pillow>=9.2.0",
"django-appconf>=1.0.5",
],
zip_safe=False,
)

View file

@ -38,6 +38,7 @@ TEMPLATES = [
"context_processors": [
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
"django.template.context_processors.request",
]
},
}

View file

@ -217,7 +217,6 @@ class AvatarTests(TestCase):
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)
@ -228,6 +227,7 @@ class AvatarTests(TestCase):
)
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)