3

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?

loneraver
  • 1,282
  • 2
  • 15
  • 22
  • Sorry, I don't speak Python, and I can't understand the documentation for Wand. However, the thing you are looking for is a `define`, or an `option` which would be specified on the ImageMagick command-line as `-define quantum:polarity=min-is-white`. So if you can find out how to set defines or options, e.g. `-define jpeg:extent=100KB` you should be able to do the same thing with the polarity. Hope that helps. @emcconville will know how to do it... – Mark Setchell Feb 22 '16 at 09:35
  • That's exactly right @MarkSetchell ! – emcconville Mar 04 '16 at 17:12

1 Answers1

2

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

For , 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
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • Yay! I was just about to post that I figured out the answer and I see that we came to the same solution. Awesome – loneraver Mar 07 '16 at 22:33