MagickFlattenImages stopped working as expected

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
golanp@wix.com
Posts: 5
Joined: 2011-06-14T01:31:04-07:00
Authentication code: 8675308

MagickFlattenImages stopped working as expected

Post by golanp@wix.com » 2012-05-15T03:28:56-07:00

Hello,

I am using MagickWand in my python application (using pythonmagicjwand).

One thing that my application does is taking an image, resize it and saves the resized image to disk.
Since I also works with PNG files which might have transparency in them, after the resize, I am setting the white background and use MagickFlattenImages so I can get a white background.

This worked perfectly with the following setup:
libMagickCore3
ii imagemagick 8:6.6.0.4-3 image manipulation programs
ii libmagickcore3 8:6.6.0.4-3 low-level image manipulation library
ii libmagickcore3-extra 8:6.6.0.4-3 low-level image manipulation library - extra codecs
ii libmagickwand3 8:6.6.0.4-3 image manipulation library

libjpng1.2:
ii libpng12-0 1.2.44-1 PNG library - runtime


Since I moved to ImageMagick 6.6.8-6 (from source), libpng-1.5.1:
Calling MagickFlattenImages makes the resized image black - the entire image is black rectangle not only the background.

Running convert from the command line yields the required result but it seems that the MagickFlattenImages API was broken.

I also tried using the newer API MergeImageLayers with FlattenLayer method.
This also occurs with the latest version: ImageMagick 6.7.6-9, libpng-1.5.10.


Please assist....

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: MagickFlattenImages stopped working as expected

Post by anthony » 2012-05-20T20:24:37-07:00

Some sample code and sample image?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

golanp@wix.com
Posts: 5
Joined: 2011-06-14T01:31:04-07:00
Authentication code: 8675308

Re: MagickFlattenImages stopped working as expected

Post by golanp@wix.com » 2012-05-31T03:08:08-07:00

Here is a Python sample code:

Code: Select all

from pythonmagickwand.image import Image

icon = Image('/tmp/image.jpg')
icon.thumbnail(100, 100)
flattenIcon = icon.flatten()
flattenIcon.save('/tmp/icon_image.jpg')
Sample file can be found here:
https://docs.google.com/open?id=0B5qM0b ... E0yQzNLQWM

save it to /tmp/image.jpg

PythonMagickWand can be found at:
http://www.assembla.com/spaces/pythonmagickwand/wiki

And installed by (make sure svn is installed)
easy_install http://svn2.assembla.com/svn/pythonmagickwand/trunk

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: MagickFlattenImages stopped working as expected

Post by anthony » 2012-05-31T17:27:41-07:00

JPEG images have no alpha. Nor do they have multiple images.

Flatten will in such a case do its job, but the result will be exactly as the original -- no change.

I assume you have extra processing steps between the thumbnail and the flatten.
Or perhaps may read PNG or GIF images and save as JPG?


If you want to get rid of transparency the new way to do this is to use the Alpha Operator method "remove".
I do not know the function name in Magick API.

This also does a background color underlay, but does it without extra image creation or full composition, but just direct changes to the given image. - A lot faster and memory efficient.

See Command line examples on -alpha remove
http://www.imagemagick.org/Usage/masking/#alpha_remove

Flatten does the same thing for single images (with transparency). But that its not its primary job, just a secondary side effect.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

golanp@wix.com
Posts: 5
Joined: 2011-06-14T01:31:04-07:00
Authentication code: 8675308

Re: MagickFlattenImages stopped working as expected

Post by golanp@wix.com » 2012-06-18T04:49:15-07:00

Thanks Anthony. You were most helpful.

Post Reply