From 9dc6fbc6b99e767e4e2bbf56d942e1c50fea5dfe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 May 2016 19:36:13 +0530 Subject: [PATCH] ... --- src/calibre/utils/img.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 747a9ac8d0..d55ff4e9ce 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -277,10 +277,14 @@ def normalize(img): raise RuntimeError(imageops_err) return imageops.normalize(image_from_data(img)) -def quantize(img, colors=256, dither=True, palette=''): - ''' Quantize the image to contain a maximum of `colors` colors. By default a palette is chosen automatically, - if you want to use a fixed palette, then pass in a list of color names in the `palette` variable. If you, - specify a palette `colors` is ignored. For example: palette='red green blue #eee' ''' +def quantize(img, max_colors=256, dither=True, palette=''): + ''' Quantize the image to contain a maximum of `max_colors` colors. By + default a palette is chosen automatically, if you want to use a fixed + palette, then pass in a list of color names in the `palette` variable. If + you, specify a palette `max_colors` is ignored. Note that it is possible + for the actual number of colors used to be less than max_colors. + + For example: palette='red green blue #eee' ''' if imageops is None: raise RuntimeError(imageops_err) img = image_from_data(img) @@ -288,7 +292,7 @@ def quantize(img, colors=256, dither=True, palette=''): img = blend_image(img) if palette and isinstance(palette, basestring): palette = palette.split() - return imageops.quantize(img, colors, dither, [QColor(x).rgb() for x in palette]) + return imageops.quantize(img, max_colors, dither, [QColor(x).rgb() for x in palette]) # Optimization of images {{{