How to center text after offsetting
Posted: 2010-05-25T19:21:22-07:00
Hi, I am new to the forum but have used the ImageMagick site often to learn and create different php scripts using IM.
I am currently working on a php script to add text on graphics, and I am trying to determine if there is a method to keep the text centered when offsetting the starting location to the east or west.
This is how I add text to the image:
-gravity $loca1 -fill rgb\($red,$green,$blue\) -annotate +$x+$y '$text'
I supply the gravity location, the x & y parameters and text via php variables.
When I choose Center for gravity and then offset x, the text it is no longer centered. Is there a argument or some formula I can apply/include that could take into account this offset while keeping the text centered so no matter the length of the text entered it would still be centered instead of starting x amount of pixels from center of the image?
Can the center coordinates be accessed from ImageMagick? If so, could the offset be added to the center x coordinate to move the text however many pixels to the left or right but keep it centered?
Thanks,
Teresa
I am currently working on a php script to add text on graphics, and I am trying to determine if there is a method to keep the text centered when offsetting the starting location to the east or west.
This is how I add text to the image:
-gravity $loca1 -fill rgb\($red,$green,$blue\) -annotate +$x+$y '$text'
I supply the gravity location, the x & y parameters and text via php variables.
When I choose Center for gravity and then offset x, the text it is no longer centered. Is there a argument or some formula I can apply/include that could take into account this offset while keeping the text centered so no matter the length of the text entered it would still be centered instead of starting x amount of pixels from center of the image?
Can the center coordinates be accessed from ImageMagick? If so, could the offset be added to the center x coordinate to move the text however many pixels to the left or right but keep it centered?
Thanks,
Teresa