PNG Transparency to JPG - Halo Ring Problem

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
rendermagic
Posts: 2
Joined: 2012-04-05T23:31:36-07:00
Authentication code: 8675308

PNG Transparency to JPG - Halo Ring Problem

Post by rendermagic »

I'm stuck and can't figure out how to get a transparent PNG to convert to a JPG. When I do a straight convert, I get this strange grey halo around the outer edge of the object in the image.

Ultimately, I'm trying to take my transparent PNG, apply a white background, and convert it to a JPG. I followed this

Any ideas?

Source Original PNG Image: http://www.carametrix.com/ExampleImageSource.png
Resulting Problem JPG Image: http://www.carametrix.com/ExampleImageResult.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG Transparency to JPG - Halo Ring Problem

Post by fmw42 »

try

convert ExampleImageSource.png +repage -background white -flatten ExampleImageSource.jpg


see
http://www.imagemagick.org/Usage/layers/#flatten


The +repage is needed to remove the virtual canvas on your png so that your jpg does not have a lot of extra white space all around it.
rendermagic
Posts: 2
Joined: 2012-04-05T23:31:36-07:00
Authentication code: 8675308

Re: PNG Transparency to JPG - Halo Ring Problem

Post by rendermagic »

Wow...that worked! That was incredibly helpful. Thank you for your help.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PNG Transparency to JPG - Halo Ring Problem

Post by anthony »

The correct way is to use -alpha remove

See Removing Transparency from Images
http://www.imagemagick.org/Usage/masking/#remove

The flatten method works though uses more memory and processing and can go wrong in specific situations as you are applying a operator that is not actually designed for removing transparency, it is just a side-effect of what its real purpose is.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: PNG Transparency to JPG - Halo Ring Problem

Post by fmw42 »

anthony wrote:The correct way is to use -alpha remove
Perhaps you should mention at what version of IM -alpha remove was added. Is it not relatively recent (6.7.5.x), but what minor version? Changelog says 6.7.5-1

P.S. It is not even listed as an option at http://www.imagemagick.org/script/comma ... .php#alpha
Post Reply