-compose plus on transparent canvas

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
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

-compose plus on transparent canvas

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -compose plus on transparent canvas

Post 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.
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: -compose plus on transparent canvas

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -compose plus on transparent canvas

Post 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?
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -compose plus on transparent canvas

Post 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?
snibgo's IM pages: im.snibgo.com
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: -compose plus on transparent canvas

Post by higoka »

I need it like the image with skyblue background but transparent so that it only shows the light
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: -compose plus on transparent canvas

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -compose plus on transparent canvas

Post 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
higoka
Posts: 17
Joined: 2019-04-22T16:36:51-07:00
Authentication code: 1152

Re: -compose plus on transparent canvas

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -compose plus on transparent canvas

Post by fmw42 »

Your approach is only part of what I did. I know no other shorter way.
Post Reply