Page 1 of 1

-compose plus on transparent canvas

Posted: 2019-04-24T12:39:29-07:00
by higoka
I want to compose a g_4_1.png over a blank transparent canvas using composition "plus". The problem is if i use a transparent canvas the image just gets copied over the canvas and fills the background black. But if i use a background color for example "skyblue" for the canvas it displays the image how i want it whitout the black background.

Using "transparent"
ImageUsing "skyblue"
Image

I dont know if this is a bug with imagemagick or the g_4_1.png has some sort of "filter" or "mask" on top of it. Could it be a bug with the plus composition, adding transparent pixel to colorized pixel

Here is the image i want to compose over the canvas.
https://ufile.io/sy2em9yh

This is the command

Code: Select all

magick -size 100x100 canvas:transparent \
   img/g_4_1.png -compose plus -composite \
   img/result_0.png

Re: -compose plus on transparent canvas

Posted: 2019-04-24T12:47:44-07:00
by fmw42
Your image is opaque. When you add opaque black to anything it is adding opaque 0. So when you add opaque 0 on a transparent background it will still be black since you are composing an opaque image onto transparency. Thus the transparency is lost in that region.

When you add opaque black it over opaque blue, you add 0 and thus do not change the blue.

Re: -compose plus on transparent canvas

Posted: 2019-04-24T12:51:17-07:00
by higoka
Whats the best way to convert the opaque to transparent and then compose it? Should i create a canvas using opaque and set opacity to 0 ?

I tried:

Code: Select all

magick -size 100x100 canvas:transparent \
   \( img/g_4_1.png -transparent white \) -compose plus -composite \
   img/result_0.png

Re: -compose plus on transparent canvas

Posted: 2019-04-24T12:54:58-07:00
by snibgo
As Fred says. (We often cross-post.)

"-compose Plus -composite" simply adds values, when both inputs are opaque. But when at least one has transparency, inputs are "pre-multiplied" by alpha, and the result is "post-divided" by the sum of the alphas.

g_4_1.png is fully opaque. Composite this with "plus" on a transparent-black, and the result is the same as g_4_1.png. It doesn't "fill the background black". I can't see a bug.

What result do you want?

Re: -compose plus on transparent canvas

Posted: 2019-04-24T12:56:51-07:00
by snibgo
I don't know why you want to add an image to a transparent canvas. Can you explain what you want from this?

Re: -compose plus on transparent canvas

Posted: 2019-04-24T12:58:00-07:00
by higoka
I need it like the image with skyblue background but transparent so that it only shows the light

Re: -compose plus on transparent canvas

Posted: 2019-04-24T13:06:16-07:00
by higoka
I first create the dragon image from some PNGs. Then i create the animation of the flame. And after that i compose both together.
But g_4_1.png has this black pixels which need to be transparent.

Code: Select all

#!/bin/sh

# Compose the dragon
magick -size 300x300 canvas:transparent \
  img/a_4_0.png -geometry +122+137 -compose over -composite \
  \( img/b_4_0.png \( +clone -fill 'gold' -colorize 100% \) -compose multiply -composite \) -geometry +132+115 -compose over -composite \
  \( img/c_4_1.png \( +clone -fill 'gold' -colorize 100% \) -compose multiply -composite \) -geometry +142+81 -compose over -composite \
  img/d_4_0.png -geometry +133+116 -compose plus -composite \
  img/e_4_1.png -geometry +143+82 -compose plus -composite \
  img/g_4_1.png -geometry +125+36 -compose plus -composite \
  img/result_1.png

# Animation of flame
magick -delay 0 -size 100x100 \
  \( img/f_4_0.png -page +122+148 -composite \) \
  \( img/f_4_1.png -page +147+54 -composite \) \
  \( img/f_4_2.png -page +145+59 -composite \) \
  \( img/f_4_3.png -page +143+56 -composite \) \
  \( img/f_4_4.png -page +142+55 -composite \) \
   -loop 0 img/result_2.gif

# Result
magick img/result_1.png null: img/result_2.gif -layers composite \
  -set dispose background -delete 0 img/final.gif
zip with all resources
https://ufile.io/2he7ii9c

final image
Image

Re: -compose plus on transparent canvas

Posted: 2019-04-24T13:30:09-07:00
by fmw42
I showed you how to do it properly in a previous post. Look at the last example I made for you in your other post.

See the code at viewtopic.php?f=1&t=35893&start=15#p165288

Re: -compose plus on transparent canvas

Posted: 2019-04-24T13:34:40-07:00
by higoka
I saw it but is there not another way which make the light display correct.

If i add -transparent black i get a better result but not perfect.
Image

Re: -compose plus on transparent canvas

Posted: 2019-04-24T15:30:03-07:00
by fmw42
Your approach is only part of what I did. I know no other shorter way.