Chaining commands woes

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
dwkns
Posts: 2
Joined: 2013-12-02T08:32:40-07:00
Authentication code: 6789

Chaining commands woes

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

Re: Chaining commands woes

Post 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.
snibgo's IM pages: im.snibgo.com
dwkns
Posts: 2
Joined: 2013-12-02T08:32:40-07:00
Authentication code: 6789

Re: Chaining commands woes

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

Re: Chaining commands woes

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply