Skip to content

Commit

Permalink
Convert thumbnails to the format specified in the options
Browse files Browse the repository at this point in the history
  • Loading branch information
gruy committed Dec 25, 2023
1 parent 39789d7 commit 37870d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions djangocms_picture/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PicturePlugin(CMSPluginBase):
'external_picture',
'is_lightbox',
'use_likes',
'convert_thumbnail_to',
)
}),
('Подпись', {
Expand Down
20 changes: 17 additions & 3 deletions djangocms_picture/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ def get_templates():
('no', _('No')),
)

CONVERT_THUMBNAIL_TO_DEFAULT = 'default'
CONVERT_THUMBNAIL_TO_WEBP = 'webp'
CONVERT_THUMBNAIL_TO = (
(CONVERT_THUMBNAIL_TO_DEFAULT, _('Default settings')),
(CONVERT_THUMBNAIL_TO_WEBP, 'WEBP'),
)


class AbstractPicture(CMSPlugin):
"""
Expand Down Expand Up @@ -234,8 +241,13 @@ class AbstractPicture(CMSPlugin):
show_title = models.BooleanField('Показывать подпись', default=False)
title = models.CharField('Заголовок', max_length=255, blank=True)
text = models.TextField('Тело подписи', max_length=2048, blank=True)

use_likes = models.BooleanField('включить "лайки"', default=False)
convert_thumbnail_to = models.CharField(
'преобразовывать в другой формат',
max_length=16,
choices=CONVERT_THUMBNAIL_TO,
default=CONVERT_THUMBNAIL_TO_DEFAULT,
)

class Meta:
abstract = True
Expand Down Expand Up @@ -380,7 +392,7 @@ def img_srcset_data(self):
thumbnailer = get_thumbnailer(self.picture)
picture_options = self.get_size(self.width, self.height)
picture_width = picture_options['size'][0]
thumbnail_options = {'crop': picture_options['crop']}
thumbnail_options = {'crop': picture_options['crop'], 'convert_thumbnail_to': self.convert_thumbnail_to}
breakpoints = getattr(
settings,
'DJANGOCMS_PICTURE_RESPONSIVE_IMAGES_VIEWPORT_BREAKPOINTS',
Expand All @@ -402,7 +414,7 @@ def img_srcset_dark_data(self):
thumbnailer = get_thumbnailer(self.picture_dark)
picture_options = self.get_size(self.width, self.height)
picture_width = picture_options['size'][0]
thumbnail_options = {'crop': picture_options['crop']}
thumbnail_options = {'crop': picture_options['crop'], 'convert_thumbnail_to': self.convert_thumbnail_to}
breakpoints = getattr(
settings,
'DJANGOCMS_PICTURE_RESPONSIVE_IMAGES_VIEWPORT_BREAKPOINTS',
Expand Down Expand Up @@ -439,6 +451,7 @@ def img_src(self):
'crop': picture_options['crop'],
'upscale': picture_options['upscale'],
'subject_location': self.picture.subject_location,
'convert_thumbnail_to': self.convert_thumbnail_to,
}

thumbnailer = get_thumbnailer(self.picture)
Expand Down Expand Up @@ -468,6 +481,7 @@ def img_src_dark(self):
'crop': picture_options['crop'],
'upscale': picture_options['upscale'],
'subject_location': self.picture_dark.subject_location,
'convert_thumbnail_to': self.convert_thumbnail_to,
}

thumbnailer = get_thumbnailer(self.picture_dark)
Expand Down

0 comments on commit 37870d2

Please sign in to comment.