Skip to content

Commit

Permalink
fix: temporary fix for issue #34
Browse files Browse the repository at this point in the history
Because Wand 0.7.0 probably won't be released in near future, we need to apply this workaround for now to support every colorspace.
  • Loading branch information
tfuxu committed Jan 10, 2024
1 parent 059ea9d commit b991d59
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions halftone/backend/magick.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ def dither_image(self, path: str, output_options: OutputOptions) -> str:
else:
new_height = int(height)

# TODO: Remove `colorspace_type` parameter on Wand 0.7.0 release.
# See: https://github.com/emcconville/wand/issues/644
with img.convert("tiff").clone() as clone:
clone.resize(width=new_width, height=new_height)
clone.brightness_contrast(float(brightness), float(contrast))
# Available error correction dither algorithms: floyd_steinberg, riemersma (More info: https://docs.wand-py.org/en/0.6.11/wand/image.html#wand.image.DITHER_METHODS)
# Available ordered dithers: https://docs.wand-py.org/en/0.6.11/wand/image.html#wand.image.BaseImage.ordered_dither
if algorithm == "ordered":
clone.ordered_dither("o4x4")
clone.quantize(color_amount)
clone.quantize(color_amount, colorspace_type="undefined")
else:
clone.quantize(color_amount, dither=algorithm)
clone.quantize(color_amount, colorspace_type="undefined", dither=algorithm)

temp_path = HalftoneTempFile().create_temp_file()
clone.save(filename=temp_path)
Expand Down

0 comments on commit b991d59

Please sign in to comment.