3

I'm working on a tool that cuts a large image into smaller tiles using ImageMagick via Python. And I need all the tiles to be on the same format (png, 8 or 16 bits).

In most case, it works just fine, but on monochromatic tiles ImageMagick compresses the picture on writing the file. For instance, pure black tiles are compressed to a 1 bit picture.

I use the plain save method, as explained in the docs.

I found no documentation about this autocompressing feature nor any way to avoid this.

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

edit:

For instance, if I use this code to import a 24bit rgb picture:

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

Once again I get

bilevel

If I try to force the pixel depth like this,

img.depth = 16

print img.type
print img.depth

I get:

bilevel
16

I thought that maybe it actually changed the depth, but once I save the image, it become 1 bit depth again.

So it seems to me that ImageMagick just automatically compresses the picture and that I have no control over it. It even refuses to change the image type.

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

ydaetskcoR
  • 53,225
  • 8
  • 158
  • 177
  • Can you provide example code, or the output your expecting? An all black 8-bit PNG would have the channel depth of 1 bit. No auto-compressing feature required. – emcconville Apr 29 '15 at 01:29
  • Thanks for your comment. I added a code example. The problem I have is that I don't want the picture to be compressed on 1 bit. I want it to have a specific depth. – arnould paul Apr 29 '15 at 08:56

0 Answers0