Page 1 of 1

Chaining commands woes

Posted: 2013-12-02T08:38:50-07:00
by dwkns
I can't figure out how to properly chain commands in ImageMagick

Things that do what I expect in isolation :

Resize and then crop

Code: Select all

$ convert input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage output.jpg
Apply overlay

Code: Select all

$ convert -composite input.jpg overlay.png output.jpg
Annotate

Code: Select all

$ convert input.jpg -annotate +55+357 'The text I want' output.jpg
I've had limited success in combining these together for instance :

Code: Select all

$ convert \( input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage \) mask.png -composite output.jpg
Resizes the image and crops it, then applies my overlay. However regardless of what I try I can't then get the annotation to appear.

What I want to do is something like :

Code: Select all

$ convert \( input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage \) mask.png -composite \( -annotate +55+357 'The text I want' \) output.jpg
Any help would be much appreciated. Thanks

-dwkns

Re: Chaining commands woes

Posted: 2013-12-02T09:06:08-07:00
by snibgo
If I understand what you want to do, you shouldn't need any parentheses.

You want to:
read input.jpg
resize it
crop it
read mask.png, so you now have two images in memory
composite the two images, using the default compose method "over", so you now have one image in memory
annotate

However, your annotate won't work if input.jpg is too small.

EDIT: Oops, I missed a problem. You probably want "-gravity NorthWest" before the annotate.

Re: Chaining commands woes

Posted: 2013-12-02T09:31:30-07:00
by dwkns
Boom!

'-gravity NorthWest' was exactly what I needed. I'm assuming this is needed because after the crop and resize, the reference point at which IM calculates the annotation position from changes?

But regardless thank you.

Re: Chaining commands woes

Posted: 2013-12-02T09:58:41-07:00
by snibgo
Not exactly. It's because your combined command contains "-gravity center", and this will apply for the rest of the command or until a different "-gravity" is specified.

The default gravity is "NorthWest", which is why it isn't needed in the simple command with annotate.