1
0
mirror of https://github.com/ciromattia/kcc synced 2025-12-13 01:36:27 +00:00

add --mozjpeg option and GUI checkBox

This commit is contained in:
darodi
2022-04-10 17:43:21 +02:00
parent 6cd073809e
commit 79715c6a06
7 changed files with 41 additions and 6 deletions

View File

@@ -18,8 +18,9 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import io
import os
import mozjpeg_lossless_optimization
from PIL import Image, ImageOps, ImageStat, ImageChops, ImageFilter
from .shared import md5Checksum
@@ -244,7 +245,15 @@ class ComicPage:
self.image.save(self.targetPath, 'PNG', optimize=1)
else:
self.targetPath += '.jpg'
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85)
if self.opt.mozjpeg:
with io.BytesIO() as output:
self.image.save(output, format="JPEG", optimize=1, quality=85)
input_jpeg_bytes = output.getvalue()
output_jpeg_bytes = mozjpeg_lossless_optimization.optimize(input_jpeg_bytes)
with open(self.targetPath, "wb") as output_jpeg_file:
output_jpeg_file.write(output_jpeg_bytes)
else:
self.image.save(self.targetPath, 'JPEG', optimize=1, quality=85)
return [md5Checksum(self.targetPath), flags, self.orgPath]
except IOError as err:
raise RuntimeError('Cannot save image. ' + str(err))