compose "over" + convert png->jpg + white background

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
abeering
Posts: 8
Joined: 2018-10-18T14:58:06-07:00
Authentication code: 1152

compose "over" + convert png->jpg + white background

Post by abeering »

Hey imagemagick dudes,

I'm struggling here to figure out what I'm doing wrong.

So first I just wanted to compose two png layers over one another and convert to jpg:

Code: Select all

convert ./1.png ./2.png -compose over -composite 3.jpg
This works fine, but the background is black, and I want it to be white. I found through some other answers that I can use "flatten" to solve this, but I think that's strictly for conversion and not composition over.

Code: Select all

convert -background white -flatten ./1.png ./2.png -compose over -composite 3.jpg
This fails.

I'm figuring there is something I need to do using parentheses, or to first convert and then compose, or something like that. But I'm having a hard time figuring what's best to do? Ideas?

P.S This is an example of two layers, but I also need to do images with up to 10 layers.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: compose "over" + convert png->jpg + white background

Post by snibgo »

Before you write the JPEG, flatten against white:

Code: Select all

{...} -background White -layers Flatten out.jpg
Yes, you had this, but in the wrong place.
snibgo's IM pages: im.snibgo.com
Post Reply