Python: monochrome monoblock wand autocompress on export. Any workaround?

I am working on a tool that slices a large image into smaller pieces using ImageMagick via Python. And I need all tiles to be in the same format (png, 8 or 16 bit).

Most of the time it works fine, but on monochromatic slabs ImageMagick compresses the image when the file is written. For example, pure black tiles are compressed to a 1-bit image.

I am using a simple save method as described in.

I have not found any documentation about this autosave feature and how to avoid it.

Is there a workaround for this or a way I can avoid this?

change

For example, if I use this code to import a 24bit rgb image:

from wand.image import Image

img = Image(filename ='http://upload.wikimedia.org/wikipedia/commons/6/68/Solid_black.png')

print img.type

      

I get this as type

   bilevel

      

if i add this,

img.type = 'grayscale'

print img.type

      

Again I get

bilevel

      

If I try to force a pixel depth like this,

img.depth = 16

print img.type
print img.depth

      

I get:

bilevel
16

      

I thought that maybe this did change the depth, but as soon as I save the image it becomes 1 bit depth again.

It seems to me that ImageMagick is just automatically compressing the image and that I have no control over it. He even refuses to change the image type.

Any ideas to avoid this? Any way to force pixel depth?

+3


source to share





All Articles