From accb5a918726ea704adff4929c0d8749674111c8 Mon Sep 17 00:00:00 2001 From: rr- Date: Thu, 2 Jun 2016 11:52:54 +0200 Subject: [PATCH] server/images: fix transaprent background for JPEG --- server/szurubooru/func/images.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index 20b21652..4bb580cd 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -48,20 +48,26 @@ class Image(object): assert self.content self._reload_info() - def _to_image(self, codec): + def to_png(self): return self._execute([ '-i', '{path}', '-f', 'image2', '-vframes', '1', - '-vcodec', codec, + '-vcodec', 'png', '-', ]) - def to_png(self): - return self._to_image('png') - def to_jpeg(self): - return self._to_image('mjpeg') + return self._execute([ + '-f', 'lavfi', + '-i', 'color=white:s=%dx%d' % (self.width, self.height), + '-i', '{path}', + '-f', 'image2', + '-filter_complex', 'overlay', + '-vframes', '1', + '-vcodec', 'mjpeg', + '-', + ]) def _execute(self, cli, program='ffmpeg'): extension = mime.get_extension(mime.get_mime_type(self.content))