Paranthesis + geometry?

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
juman
Posts: 6
Joined: 2017-10-22T11:08:36-07:00
Authentication code: 1151

Paranthesis + geometry?

Post by juman »

I'm trying to center a character (as an image) in a box so that I then can easily reposition it in another image with one command.

So I have started by making sure a character is central in a image by doing the following (create image, enter text, crop to character, extend canvas) :

Code: Select all

convert  -size 200x200 xc:none -fill blue -font Courier-bold -pointsize 100 -gravity center -background none -annotate +0+0 b -trim -gravity center -extent 400x400 +repage b.png
Now I can easily position this box on another image like this :

Code: Select all

convert background.png b.png -geometry +200+400 -composite a_o.png
This seems to place the b-image with the geometry coords from a corner of the image.

However I would like to do this without creating a temporary file for the character so doing it all in one command so I am trying to use paranthesis.

Code: Select all

convert background.png \(  -size 200x200 xc:none -fill blue -font Courier-bold -pointsize 100 -gravity center -background none -annotate +0+0 b -trim -gravity center -extent 400x400 +repage   \)  -geometry +200+400 -composite out.png
However in this command it seems like the b-image is positoned by the geometry coords from the center of the background image? How can I avoid this and get the same result as with the previous command?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Paranthesis + geometry?

Post by fmw42 »

You need to reset the -gravity setting after the parenthesis or it will carry beyond the parenthesis. The default for -gravity is northwest.

Code: Select all

convert background.png \
\(  -size 200x200 xc:none -fill blue -font Courier-bold -pointsize 100 -gravity center -annotate +0+0 "b" \
-trim +repage -gravity center -background none -extent 400x400  \) +gravity -geometry +200+400 -composite out.png
or

Code: Select all

convert background.png \
\(  -size 200x200 xc:none -fill blue -font Courier-bold -pointsize 100 -gravity center -annotate +0+0 "b" \
-trim +repage -gravity center -background none -extent 400x400  \) -gravity northwest -geometry +200+400 -composite out.png
or add -respect-parentheses (though for some options that does not always work). See http://www.imagemagick.org/script/comma ... arentheses

Code: Select all

convert -respect-parenthesis background.png \
\(  -size 200x200 xc:none -fill blue -font Courier-bold -pointsize 100 -gravity center -annotate +0+0 "b" \
-trim +repage -gravity center -background none -extent 400x400  \) -geometry +200+400 -composite out.png
juman
Posts: 6
Joined: 2017-10-22T11:08:36-07:00
Authentication code: 1151

Re: Paranthesis + geometry?

Post by juman »

Ah, got it! Thanks!
Post Reply