Join Commands.

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
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Join Commands.

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

Re: Join Commands.

Post 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.
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

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

Re: Join Commands.

Post 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.
snibgo's IM pages: im.snibgo.com
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

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

Re: Join Commands.

Post 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.
snibgo's IM pages: im.snibgo.com
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

Post by raabik »

.
Last edited by raabik on 2019-05-14T10:45:34-07:00, edited 1 time in total.
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

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

Re: Join Commands.

Post 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
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

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

Re: Join Commands.

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

Re: Join Commands.

Post 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
raabik
Posts: 9
Joined: 2019-04-11T12:28:31-07:00
Authentication code: 1152

Re: Join Commands.

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

Re: Join Commands.

Post 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
Post Reply