From 3a0f3349706bff5fe275396307b834d987962f43 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Fri, 10 Oct 2014 20:54:47 +0200 Subject: [PATCH 1/2] optimizeimages: Add jpegoptim interface Only options that appear to be interesting for us have been exposed, namely -m and -S. --- overviewer_core/optimizeimages.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/overviewer_core/optimizeimages.py b/overviewer_core/optimizeimages.py index 0ccd4a2..af56039 100644 --- a/overviewer_core/optimizeimages.py +++ b/overviewer_core/optimizeimages.py @@ -120,6 +120,42 @@ class optipng(Optimizer, PNGOptimizer): def is_crusher(self): return True + +class jpegoptim(Optimizer, JPEGOptimizer): + binaryname = "jpegoptim" + crusher = True + quality = None + target_size = None + + def __init__(self, quality = None, target_size = None): + if quality is not None: + if quality < 0 or quality > 100: + raise Exception("Invalid target quality %d for jpegoptim" % quality) + self.quality = quality + + if target_size is not None: + self.target_size = target_size + + def optimize(self, img): + args = [self.binaryname, "-q", "-p"] + if self.quality is not None: + args.append("-m" + str(self.quality)) + + if self.target_size is not None: + args.append("-S" + str(self.target_size)) + + args.append(img) + + Optimizer.fire_and_forget(self, args) + + def is_crusher(self): + # Technically, optimisation is lossless if input image quality + # is below target quality, but this is irrelevant in this case + if (self.quality is not None) or (self.target_size is not None): + return False + else: + return True + def optimize_image(imgpath, imgformat, optimizers): From 79e60972e91ab25762a67ce5f9056010d85c3a7d Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Fri, 10 Oct 2014 21:10:07 +0200 Subject: [PATCH 2/2] optimizeimages: Add documentation for jpegoptim --- docs/config.rst | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/config.rst b/docs/config.rst index c617f52..eaf0968 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -683,8 +683,8 @@ Image options Using image optimizers will increase render times significantly. This option specifies which additional tools overviewer should use to - optimize the filesize of png tiles. - The tools used must be placed somewhere, where overviewer can find them, for + optimize the filesize of rendered tiles. + The tools used must be placed somewhere where overviewer can find them, for example the "PATH" environment variable or a directory like /usr/bin. The option is a list of Optimizer objects, which are then executed in @@ -766,6 +766,34 @@ Image options **Default:** ``False`` + ``jpegoptim`` + jpegoptim can do both lossy and lossless JPEG optimisation. If no options are specified, + jpegoptim will only do lossless optimisations. + Available settings: + + ``quality`` + A number between 0 and 100 that corresponds to the jpeg quality level. If the input + image has a lower quality specified than the output image, jpegoptim will only do + lossless optimisations. + + If this option is specified and the above condition does not apply, jpegoptim will + do lossy optimisation. + + **Default:** ``None`` *(= Unspecified)* + + ``target_size`` + Either a percentage of the original filesize (e.g. ``"50%"``) or a target filesize + in kilobytes (e.g. ``15``). jpegoptim will then try to reach this as its target size. + + If specified, jpegoptim will do lossy optimisation. + + .. warning:: + This appears to have a greater performance impact than just setting ``quality``. + Unless predictable filesizes are a thing you need, you should probably use ``quality`` + instead. + + **Default:** ``None`` *(= Unspecified)* + **Default:** ``[]`` Zoom