-2

I can force text into the proper position using actual numeric values for X and Y in -annotate +X+Y, but I want to be able to compute the X and Y values (in my program) relative to the image size. I am using -gravity Northeast and NorthWest for both vertical and horizontal images of varying sizes. I want to be able to have the text inset a computed number of pixels from the edges of the image RELATIVE to the image size. In my testing, it seems that when using SouthEast, the X value I insert manually is relative to the right-hand edge of the image, which is counter-intuitive. Am I right?

I originally tried to set a margin from the left edge of the image, but that got strange results. So I tried using -gravity SouthEast -annotate +5+Y and got a right-hand margin of 5 pixels. When I changed to -annotate +7+Y I got a right-hand margin of 7 pixels. So I guess I don't really understand the X values when using -gravity.

This is the full parameter string I am passing to mogrify:

mogrify in.jpg -format jpg -font "Rockwell" -weight ExtraBold -fill gold -pointsize 63 ^ -stroke black 13 -strokewidth 14 -gravity SouthEast -annotate +5+100 “text1” ^ -stroke none -gravity SouthEast -annotate +5+100 ”text1” E:\\folders\\parent\\child1\\in.jpg
1
  • The origin is relative to the -gravity position. Commented Aug 19, 2024 at 17:28

1 Answer 1

1

Maybe you can see better if I draw some text with 2 different gravity settings and show the anchor point in red:

magick -size 640x480 xc:yellow \
  -font Roboto-Regular.ttf -pointsize 36 \
  -gravity northwest -annotate +40+10 "NW +40+10" \
  -gravity southeast -annotate +80+10 "SE +80+10" \
  -fill red \
  -draw "circle 40,10 40,15" \
  -draw "circle 560,470 560,475" result.png

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.