Snowball
Snowball

Reputation: 1248

Multiple Commands with ImageMagick

I have the following files: background.jpg element1.jpg element2.jpg

I would like to take element1.jpg, resize it to 300x300, place it on background.jpg, and then take element2.jpg, resize it to 400x400 and place it on the background. I would NOT like the background to be resized.

This is my current command. It appears that resize 400x400! is applied to all the previous images in memory (background.jpg and element1.jpg), instead of one specific image.

convert background.jpg -page +0+0 -resize 300x300! element1.jpg -page +0+0 -resize 400x400! element2.jpg -layers flatten output.jpg

Is there a way to accomplish this without creating a tmp folder to save "middle steps" and have it done all in one command? Or, is there a way to use "brackets" to specify which commands to run first?

Upvotes: 2

Views: 3502

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 208077

You can use parentheses to ensure operators only apply to specific images, like this:

convert background.jpg \
   \( element1.jpg -resize NNN \) -composite \
   \( element2.jpg -resize MMM \) -composite result.jpg

So, if we create 3 test images, all the same size at 600x400 pixels:

convert -size 600x400 xc:red    red.png
convert -size 600x400 xc:yellow yellow.png
convert -size 600x400 xc:blue   blue.png

We can now individually resize and position them:

convert blue.png \
   \( red.png    -resize 80x50!   \) -geometry +20+100  -composite  \
   \( yellow.png -resize 200x200! \) -geometry +200+150 -composite result.png

enter image description here

Upvotes: 4

Related Questions