Page 1 of 1

Join Commands.

Posted: 2019-05-14T08:54:03-07:00
by raabik
I have this command's:

composite -compose Multiply "b.png" "p4.png" "p0.png"
composite -compose Multiply "y.png" -negate "p4.png" "p1.png"
composite -compose Plus "p0.png" "p1.png" "final.png"

used one after one it generates my needed image, but I only need final.png. p0,p1 are not needed. How to join into one line these commands ?
I tried:

convert "b.png" "y.png" "p4.png" \
\( -clone 2 -negate \) \
\( -clone 0,2 -compose Multiply \) \
\( -clone 1,3 -compose Multiply \) \
\( -clone 4,5 -compose Plus \) \
\final.png

I use:
ImageMagick 6.8.9-9 Q16 x86_64 2018-09-28

Re: Join Commands.

Posted: 2019-05-14T08:56:38-07:00
by fmw42
Reverse the order of your pairs of images when using convert. See https://imagemagick.org/Usage/compose/#compose. Also why is there a \ before final.png?

If that does not help, then post your images to some free hosting service that won't change the format and put the URLs here.

Re: Join Commands.

Posted: 2019-05-14T09:14:40-07:00
by raabik
https://i.ibb.co/Wc0P92h/B.png <- B image
https://i.ibb.co/JvYYkw6/Y.png <- Y image
https://i.ibb.co/2t0M5t0/p4.png <- p4 image (grayscale mask)
https://i.ibb.co/NTz7jkr/final.png <- Wanted Result

I tried changing the order and removed before final "/", but I don't know if I understood it right:

convert "b.png" "y.png" "p4.png" \
\( -clone 2 -negate \) \
\( -clone 2,0 -compose Multiply \) \
\( -clone 3,1 -compose Multiply \) \
\( -clone 5,4 -compose Plus \) \
final.png

but i get error :"(: command not found" on ubuntu

Re: Join Commands.

Posted: 2019-05-14T09:30:55-07:00
by snibgo
The \ character means "the command continues on the next line" only when it is the final character of the line. Don't have a space after it.

Re: Join Commands.

Posted: 2019-05-14T09:45:42-07:00
by raabik
there is no more error with "\", thanks.

but it produces 9 images(final33-0 to 9) and none of them is like my wanted result. what can I do now ?

Re: Join Commands.

Posted: 2019-05-14T10:24:15-07:00
by snibgo
"-compose X" is a setting that is used by some operators such as "-composite". So replace "-compose Multiply" with "-compose Multiply -composite", etc.

Re: Join Commands.

Posted: 2019-05-14T10:44:31-07:00
by raabik
.

Re: Join Commands.

Posted: 2019-05-14T10:44:55-07:00
by raabik
thanks, now it works 100%! Great Forum!

convert "b.png" "y.png" "p4.png" \
\( -clone 2 -negate \) \
\( -clone 0,2 -compose Multiply -composite \) \
\( -clone 1,3 -compose Multiply -composite \) \
\( -clone 4,5 -compose Plus -composite \) \
-delete 0-5 final99.png

Re: Join Commands.

Posted: 2019-05-14T10:52:55-07:00
by fmw42
try this

Code: Select all

convert b.png p4.png \
\( -clone 0,1 -compose multiply -composite \) \
\( y.png -negate -clone 1 -compose multiply -composite \) \
-delete 0,1 \
-compose plus -composite \
final.png

Re: Join Commands.

Posted: 2019-05-14T11:26:19-07:00
by raabik
thanks fmw42, for Your reply, but this is not using "y.png"(Yellow). I mean the result is only black and blue.

https://i.ibb.co/r3W0f1f/final4.png

For now I have:

convert "b.png" "y.png" "p4.png" \
\( -clone 2 -negate \) \
\( -clone 0,2 -compose Multiply -composite \) \
\( -clone 1,3 -compose Multiply -composite \) \
\( -clone 4,5 -compose Plus -composite \) \
\( -clone 6,0 -compose CopyOpacity -composite \) \#I also needed to add this line because it happens that the alpha channel went everywhere 255, what was not intended.
-delete 0-6 final88.png

If there is an more elegant solution fmw42 please let me know.

Re: Join Commands.

Posted: 2019-05-14T11:49:47-07:00
by fmw42
See my line

Code: Select all

\( y.png -negate -clone 1 -compose multiply -composite \) \
But my code was not tested. So I could have made a mistake. Your code should be able to reduce the number of images you keep around in memory.

Re: Join Commands.

Posted: 2019-05-14T12:07:44-07:00
by fmw42
This seems to work for me to reproduce your final image.

Code: Select all

convert p4.png \
\( -clone 0 b.png -compose multiply -composite +write fred_p0.png \) \
\( -clone 0 -negate y.png -compose multiply -composite +write fred_p1.png \) \
-delete 0 \
-compose plus -composite \
fred_final.png

Re: Join Commands.

Posted: 2019-05-14T14:38:33-07:00
by raabik
Yes this new ones works, thanks. so which one should I use in my application? which one is better? I mean Yours produce two more images, but deletes only 1, mine produces only one final. so i is my better?

Re: Join Commands.

Posted: 2019-05-14T16:52:14-07:00
by fmw42
I forgot to remove the extra writes that I used for testing. Use the following:

Code: Select all

convert p4.png \
\( -clone 0 b.png -compose multiply -composite \) \
\( -clone 0 -negate y.png -compose multiply -composite \) \
-delete 0 \
-compose plus -composite \
final.png