Page 1 of 1

Paranthesis + geometry?

Posted: 2017-10-22T11:46:55-07:00
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?

Re: Paranthesis + geometry?

Posted: 2017-10-22T12:13:33-07:00
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

Re: Paranthesis + geometry?

Posted: 2017-10-22T13:43:49-07:00
by juman
Ah, got it! Thanks!