Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
funkwhale
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zwordi
funkwhale
Commits
609dd3b4
Commit
609dd3b4
authored
May 07, 2020
by
Tony Wasserka
Committed by
Agate
May 07, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase image quality of downscaled images from 70 to 95
parent
5d2e72e6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
89 additions
and
3 deletions
+89
-3
api/config/settings/common.py
api/config/settings/common.py
+4
-1
api/funkwhale_api/cli/main.py
api/funkwhale_api/cli/main.py
+1
-0
api/funkwhale_api/cli/media.py
api/funkwhale_api/cli/media.py
+58
-0
api/funkwhale_api/common/scripts/__init__.py
api/funkwhale_api/common/scripts/__init__.py
+0
-2
api/funkwhale_api/common/utils.py
api/funkwhale_api/common/utils.py
+12
-0
changes/changelog.d/thunbnails.enhancement
changes/changelog.d/thunbnails.enhancement
+1
-0
changes/notes.rst
changes/notes.rst
+13
-0
No files found.
api/config/settings/common.py
View file @
609dd3b4
...
...
@@ -1211,7 +1211,10 @@ VERSATILEIMAGEFIELD_RENDITION_KEY_SETS = {
(
"medium_square_crop"
,
"crop__200x200"
),
],
}
VERSATILEIMAGEFIELD_SETTINGS
=
{
"create_images_on_demand"
:
False
}
VERSATILEIMAGEFIELD_SETTINGS
=
{
"create_images_on_demand"
:
False
,
"jpeg_resize_quality"
:
env
.
int
(
"THUMBNAIL_JPEG_RESIZE_QUALITY"
,
default
=
95
),
}
RSA_KEY_SIZE
=
2048
# for performance gain in tests, since we don't need to actually create the
# thumbnails
...
...
api/funkwhale_api/cli/main.py
View file @
609dd3b4
...
...
@@ -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
...
...
api/funkwhale_api/cli/media.py
0 → 100644
View file @
609dd3b4
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
@
base
.
cli
.
group
()
def
media
():
"""Manage media files (avatars, covers, attachments…)"""
pass
@
media
.
command
(
"generate-thumbnails"
)
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.
"""
MODELS
=
[
(
Attachment
,
"file"
,
"attachment_square"
),
]
for
model
,
attribute
,
key_set
in
MODELS
:
click
.
echo
(
"Generating thumbnails for {}.{}…"
.
format
(
model
.
_meta
.
label
,
attribute
)
)
qs
=
model
.
objects
.
exclude
(
**
{
"{}__isnull"
.
format
(
attribute
):
True
})
qs
=
qs
.
exclude
(
**
{
attribute
:
""
})
cache_key
=
"*{}{}*"
.
format
(
settings
.
MEDIA_URL
,
vif_settings
.
VERSATILEIMAGEFIELD_SIZED_DIRNAME
)
entries
=
cache
.
keys
(
cache_key
)
if
entries
:
click
.
echo
(
" Clearing {} cache entries: {}…"
.
format
(
len
(
entries
),
cache_key
)
)
for
keys
in
common_utils
.
batch
(
iter
(
entries
)):
cache
.
delete_many
(
keys
)
warmer
=
VersatileImageFieldWarmer
(
instance_or_queryset
=
qs
,
rendition_key_set
=
key_set
,
image_attr
=
attribute
,
verbose
=
True
,
)
click
.
echo
(
" Creating images"
)
num_created
,
failed_to_create
=
warmer
.
warm
()
click
.
echo
(
" {} created, {} in error"
.
format
(
num_created
,
len
(
failed_to_create
))
)
api/funkwhale_api/common/scripts/__init__.py
View file @
609dd3b4
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__
=
[
"create_actors"
,
"create_image_variations"
,
"django_permissions_to_user_permissions"
,
"migrate_to_user_libraries"
,
"delete_pre_017_federated_uploads"
,
...
...
api/funkwhale_api/common/utils.py
View file @
609dd3b4
...
...
@@ -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
):
try
:
current
.
append
(
next
(
iterable
))
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
(
field
.
name
)
...
...
changes/changelog.d/thunbnails.enhancement
0 → 100644
View file @
609dd3b4
Increased quality of JPEG thumbnails
changes/notes.rst
View file @
609dd3b4
...
...
@@ -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 manage.py 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.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment