dwkns
dwkns

Reputation: 2449

ImageMagick chaining woes

I can't figure out how to properly chain commands in ImageMagick

Things that do what I expect in isolation :

Resize and then crop

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

Apply overlay

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

Annotate

$ convert input.jpg -annotate +55+357 'The text I want' output.jpg

I've had limited success in combining these together for instance :

$ 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 :

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

Thanks.

Upvotes: 0

Views: 157

Answers (1)

dwkns
dwkns

Reputation: 2449

Answering my own question :

Adding -gravity NorthWest before the annotation solves the problem.

$ convert input.jpg -resize '400x400>' -gravity center -crop 300x400+0+0 +repage mask.png -composite -gravity NorthWest -annotate +55+357 'The text I want' output.jpg

I believe this effectively resets the 0,0 after the crop / resize so the annotation appears where it is expected to.

Note that you don't need the parenthesis either.

Credit to snibgo on the ImageMagick forum.

Upvotes: 1

Related Questions