From fa8edce417aa3922f10900b52d5e2120a0251cd3 Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Sun, 13 Mar 2022 08:26:42 +0100 Subject: [PATCH] fix #395 --- raster_output_png.inx | 2 +- raster_output_png.py | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/raster_output_png.inx b/raster_output_png.inx index 3cfb234d..26d053ef 100644 --- a/raster_output_png.inx +++ b/raster_output_png.inx @@ -7,7 +7,7 @@ - true + false diff --git a/raster_output_png.py b/raster_output_png.py index b052bd21..b70baa0e 100755 --- a/raster_output_png.py +++ b/raster_output_png.py @@ -6,14 +6,14 @@ Optimise PNG file using optipng import os import inkex from inkex.extensions import TempDirMixin -from inkex.command import call +from inkex.command import ProgramRunError, call class PngOutput(TempDirMixin, inkex.RasterOutputExtension): def add_arguments(self, pars): pars.add_argument("--tab") # Lossless options - pars.add_argument("--interlace", type=inkex.Boolean, default=True) + pars.add_argument("--interlace", type=inkex.Boolean, default=False) pars.add_argument("--level", type=int, default=0) # Lossy options pars.add_argument("--bitdepth", type=inkex.Boolean, default=False) @@ -35,7 +35,23 @@ class PngOutput(TempDirMixin, inkex.RasterOutputExtension): "nc": not self.options.color, "np": not self.options.palette, } - call("optipng", self.png_file, oldie=True, clobber=True, **options) + try: + call("optipng", self.png_file, oldie=True, clobber=True, **options) + except ProgramRunError as err: + if "IDAT recoding is necessary" in err.stderr.decode("utf-8"): + raise inkex.AbortExtension( + _( + "The optipng command failed, possibly due to a mismatch of the" + "interlacing and compression level options. Please try to disable " + '"Interlaced" or set "Level" to 1 or higher.' + ) + ) + else: + raise inkex.AbortExtension( + _("The optipng command failed with the following message:") + + "\n" + + err.stderr.decode("utf-8") + ) if os.path.isfile(self.png_file): with open(self.png_file, "rb") as fhl: -- GitLab