Re: [GD-DEVEL] How to calculate the bounding rect for gdImageStringFT when the angle is not zero
| From: | Pierre | Date: | Wed, 27 Jun 2007 05:16:04 +0000 |
| Subject: | Re: [GD-DEVEL] How to calculate the bounding rect for gdImageStringFT when the angle is not zero | ||
| References: | 1 | Groups: | php.gd.devel |
| Request: | Send a blank email to php-gd-devel+get-213@lists.php.net to get a copy of this message | ||
On 6/26/07, Andrei Stebakov <lispercat@gmail.com> wrote:
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 textgdImageStringFt can tak a bounding rectangle as argument. When you give it, it will be filled with the bounding rectangle of a given text at a given angle. See the example here: http://www.libgd.org/OldFont#char_.2AgdImageStringFT.28gdImagePtr_im.2C_int_.2Abrect.2C_int_fg.2C_char_.2Afontname.2C_double_ptsize.2C_double_angle.2C_int_x.2C_int_y.2C_char_.2Astring.29_.28FUNCTION.29 Is it what you are looking for? Cheers, --Pierre