Python Wand change tiff to min-is-white

北战南征 提交于 2019-12-12 15:07:06

问题


I need to convert files to tiff where photometric is set "min-is-white" (white is zero) to comply with the required standards. I'm using Wand to interact with Photomagick but every I save a bilevel tiff file, it creates a min-is-black.

How can I get Wand to saves it where White is Zero? Is it even possible?


回答1:


Mark's comments are correct. You need to set the -define property for ImageMagick.

For wand, you'll have to extent the core wand.api.library to connect MagickWand's C-API MagickSetOption method.

from ctypes import c_void_p, c_char_p
from wand.api import library
from wand.image import Image

# Tell python about the MagickSetOption method
library.MagickSetOption.argtypes = [c_void_p,  # MagickWand * wand
                                    c_char_p,  # const char * option
                                    c_char_p]  # const char * value

# Read source image
with Image(filename="/path/to/source.tiff") as image:
    # -define quantum:polarity=min-is-white
    library.MagickSetOption(image.wand,          # MagickWand
                            "quantum:polarity",  # option
                            "min-is-white")      # value
    # Write min-is-white image
    image.save(filename="/path/to/min-is-white.tiff")

You can verify the resulting image with the identify utility.

identify -verbose /path/to/min-is-white.tiff | grep photometric
#=> tiff:photometric: min-is-white


来源:https://stackoverflow.com/questions/35205601/python-wand-change-tiff-to-min-is-white

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!