How to calculate the bounding rect for gdImageStringFT when the angle is not zero
[email protected] ("Andrei Stebakov")
| Newsgroups | php.gd.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi
I've been using the function gdImageStringFT for some time and it was fine
untill I started to think of how to create a text image with non-zero angle.
It looks like the bounding rect which I calculate setting gdImagePtr to NULL
doesn't take the angle into account (and it's in the spec too).
Even if I calculate the rect for zero angle text and then create an image
with max(rect-width, rect-height) I still need to know the x and y offsets.
Here is some pseudo-code how I do it:
rect = render-no-draw("some text", font, some_angle) //Calc the rect
int box_width = rect[2] - rect[0]
int box_height = rect[3] - rect[5]
int horizont_shift = rect[0]
int vertical_shift = rect[1]
im = gdImageCreate(box_width, box_height) //Create the image
int x = -horizont_shift
int y = box_height - vertical_shift
gdImageStringFT(im, "some text", ..., x, y) //Draw the text
The algorithm above works when the angle is zero, so I need to customize
somehow for non-zero angle.
1) How to calculate the image sizes in this case
2) How to calculate x and y for the angled text
Thank you,
Andrei