Commit 609dd3b4 authored by Tony Wasserka's avatar Tony Wasserka Committed by Agate

Increase image quality of downscaled images from 70 to 95

parent 5d2e72e6
......@@ -1211,7 +1211,10 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
("medium_square_crop", "crop__200x200"),
VERSATILEIMAGEFIELD_SETTINGS = {"create_images_on_demand": False}
"create_images_on_demand": False,
"jpeg_resize_quality":"THUMBNAIL_JPEG_RESIZE_QUALITY", default=95),
# for performance gain in tests, since we don't need to actually create the
# thumbnails
......@@ -3,6 +3,7 @@ import sys
from . import base
from . import library # noqa
from . import media # noqa
from . import users # noqa
from rest_framework.exceptions import ValidationError
import click
from django.core.cache import cache
from django.conf import settings
from versatileimagefield.image_warmer import VersatileImageFieldWarmer
from versatileimagefield import settings as vif_settings
from funkwhale_api.common import utils as common_utils
from funkwhale_api.common.models import Attachment
from . import base
def media():
"""Manage media files (avatars, covers, attachments…)"""
def generate_thumbnails():
Generate thumbnails for all images (avatars, covers, etc.).
This can take a long time and generate a lot of I/O depending of the size
of your library.
(Attachment, "file", "attachment_square"),
for model, attribute, key_set in MODELS:
"Generating thumbnails for {}.{}…".format(model._meta.label, attribute)
qs = model.objects.exclude(**{"{}__isnull".format(attribute): True})
qs = qs.exclude(**{attribute: ""})
cache_key = "*{}{}*".format(
entries = cache.keys(cache_key)
if entries:
" Clearing {} cache entries: {}…".format(len(entries), cache_key)
for keys in common_utils.batch(iter(entries)):
warmer = VersatileImageFieldWarmer(
click.echo(" Creating images")
num_created, failed_to_create = warmer.warm()
" {} created, {} in error".format(num_created, len(failed_to_create))
from . import create_actors
from . import create_image_variations
from . import django_permissions_to_user_permissions
from . import migrate_to_user_libraries
from . import delete_pre_017_federated_uploads
......@@ -8,7 +7,6 @@ from . import test
__all__ = [
......@@ -23,6 +23,18 @@ from django.utils import timezone
logger = logging.getLogger(__name__)
def batch(iterable, n=1):
has_entries = True
while has_entries:
current = []
for i in range(0, n):
except StopIteration:
has_entries = False
yield current
def rename_file(instance, field_name, new_name, allow_missing_file=False):
field = getattr(instance, field_name)
current_name, extension = os.path.splitext(
Increased quality of JPEG thumbnails
......@@ -5,3 +5,16 @@ Next release notes
Those release notes refer to the current development branch and are reset
after each release.
Increased quality of JPEG thumbnails [manual action required]
Default quality for JPEG thumbnails was increased from 70 to 95, as 70 was producing visible artifacts in resized images.
Because of this change, existing thumbnails will not load, and you will need to:
1. delete the ``__sized__`` directory in your ``MEDIA_ROOT`` directory
2. run ``python fw media generate-thumbnails`` to regenerate thumbnails with the enhanced quality
If you don't want to regenerate thumbnails, you can keep the old ones by adding ``THUMBNAIL_JPEG_RESIZE_QUALITY=70`` to your .env file.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment