mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
d03f4490f3
commit
9dc6fbc6b9
@ -277,10 +277,14 @@ def normalize(img):
|
|||||||
raise RuntimeError(imageops_err)
|
raise RuntimeError(imageops_err)
|
||||||
return imageops.normalize(image_from_data(img))
|
return imageops.normalize(image_from_data(img))
|
||||||
|
|
||||||
def quantize(img, colors=256, dither=True, palette=''):
|
def quantize(img, max_colors=256, dither=True, palette=''):
|
||||||
''' Quantize the image to contain a maximum of `colors` colors. By default a palette is chosen automatically,
|
''' Quantize the image to contain a maximum of `max_colors` colors. By
|
||||||
if you want to use a fixed palette, then pass in a list of color names in the `palette` variable. If you,
|
default a palette is chosen automatically, if you want to use a fixed
|
||||||
specify a palette `colors` is ignored. For example: palette='red green blue #eee' '''
|
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:
|
if imageops is None:
|
||||||
raise RuntimeError(imageops_err)
|
raise RuntimeError(imageops_err)
|
||||||
img = image_from_data(img)
|
img = image_from_data(img)
|
||||||
@ -288,7 +292,7 @@ def quantize(img, colors=256, dither=True, palette=''):
|
|||||||
img = blend_image(img)
|
img = blend_image(img)
|
||||||
if palette and isinstance(palette, basestring):
|
if palette and isinstance(palette, basestring):
|
||||||
palette = palette.split()
|
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 {{{
|
# Optimization of images {{{
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user