Composit 3 images using a single RGB mask

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?".
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

Can mogrify extract the size of the first image as well? I've been using it in other cases too btw
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

Nevermind, I found another solution :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

blurymind wrote:Nevermind, I found another solution :)
It would be nice if you provide your solution to help others.
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

My solution was to first get the image size by using
convert image -format "%w x %h" info:

Then resizing with mogrify. I however couldnt get it to do it in a single command :(

I am new to nesting commands in imagemagick - thus why i needed help for the channel mask syntax
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

In unix, you can do it in two lines for IM 7

Code: Select all

size=$(magick image1 -format "%wx%h" info:)
magick mogrify -resize "$size" .....
I do not know the syntax for Windows to save into a variable and reuse the variable.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Composit 3 images using a single RGB mask

Post by snibgo »

blurymind wrote:I am new to nesting commands in imagemagick ...
ImageMagick has no feature for nesting commands. Bash does, and bash can be used on Windows.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

In Unix, you can nest commands. For example, these should work

IM6:

Code: Select all

mogrify -resize $(convert image1 -format "%wx%h" info:) *.png

IM7:

Code: Select all

magick mogrify -resize $(magick image1 -format "%wx%h" info:) *.png
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

Its neat that imagemagick 7 has that command - it would be even better if it can also name the end files properly
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

blurymind wrote:Its neat that imagemagick 7 has that command - it would be even better if it can also name the end files properly
What command are you referring? Name them in what way?

If using mogrify, they should get the same name as the input file (and write over the input with the newone) or you can use -path to write them to an existing other (empty) directory.
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

fmw42 wrote:You have to be using IM 7 and then there is a different syntax that needs to be used.

In IM 7, you can do

Code: Select all

magick image1 -set option:mysize "%wx%h" image2 image3 ... imageN -resize "%[mysize]" result.png
You cannot do this in IM 6.

You still have not provided your IM version!
This command :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

magick or convert can only write one output name, but it can be modified. For example, I believe, you could write to x-inputname.png. But the basename "x" must be there or some other placeholder for the output name. See -set filename: at http://www.imagemagick.org/Usage/basics/#set. Unfortunately, you cannot leave some basename off.

That is why mogrify exists, to process one output for each input. Magick and convert typically only process one or more input images and generate one output image name. The nested magick inside magick mogrify does this all in one command.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composit 3 images using a single RGB mask

Post by fmw42 »

Turns out the IM 7 is more flexible than I thought in terms of writing one output for each input and making the filenames the same, though a common suffix needs to be used for the output.

So you can do this:

Code: Select all

magick rose.png -set option:mysize "%wx%h" logo.png netscape.png -set filename:f "%[t]" -resize "%[mysize]" "%[filename:f].png"
or this:

Code: Select all

magick *.png \( +clone -set option:mysize "%wx%h" +delete \) -set filename:f "%[t]" -resize "%[mysize]" "%[filename:f].png"
blurymind
Posts: 22
Joined: 2016-07-23T07:04:15-07:00
Authentication code: 1151

Re: Composit 3 images using a single RGB mask

Post by blurymind »

hi, thank you for sharing these. Glad to see IM getting better at this type of thing!! :)
Post Reply