fix gaussian blur for gifs

master
lza_menace 2 years ago
parent 3cc3a365c1
commit 335365dd24

@ -96,7 +96,7 @@ class Artwork(pw.Model):
def generate_thumbnail(self): def generate_thumbnail(self):
is_gif = self.image.endswith('.gif') is_gif = self.image.endswith('.gif')
_t = f'thumbnail-{self.image}' _t = self.thumbnail
i = f'{config.DATA_PATH}/uploads/{self.image}' i = f'{config.DATA_PATH}/uploads/{self.image}'
t = f'{config.DATA_PATH}/uploads/{_t}' t = f'{config.DATA_PATH}/uploads/{_t}'
try: try:
@ -106,22 +106,22 @@ class Artwork(pw.Model):
frames = ImageSequence.Iterator(image) frames = ImageSequence.Iterator(image)
def thumbnails(frames): def thumbnails(frames):
for frame in frames: for frame in frames:
thumbnail = frame.copy() thumbnail = frame.copy().convert('RGBA')
thumbnail.thumbnail(size, Image.ANTIALIAS) thumbnail.thumbnail(size, Image.ANTIALIAS)
if self.nsfw: if self.nsfw:
thumbnail = thumbnail.filter(ImageFilter.GaussianBlur(radius = 4)) thumbnail = thumbnail.filter(ImageFilter.GaussianBlur(radius = 6))
yield thumbnail yield thumbnail
_frames = thumbnails(frames) _frames = thumbnails(frames)
_image = next(_frames) _image = next(_frames)
_image.info = image.info _image.info = image.info
_image.save(t, save_all=True, append_images=list(_frames), disposal=2) _image.save(t, save_all=True, append_images=list(_frames), disposal=2)
_image.close()
else: else:
image.thumbnail(size, Image.ANTIALIAS) image.thumbnail(size, Image.ANTIALIAS)
if self.nsfw: if self.nsfw:
image = image.filter(ImageFilter.GaussianBlur(radius = 4)) image = image.filter(ImageFilter.GaussianBlur(radius = 6))
image.save(t, format=image.format) image.save(t, format=image.format)
image.close() image.close()
self.thumbnail = _t
self.save() self.save()
return True return True
except Exception as e: except Exception as e:

Loading…
Cancel
Save