The php text watermark is made of imagettftext. how do I calculate the width and height of the text ??

Source: Internet
Author: User
The php text watermark is made of imagettftext. how do I calculate the width and height of the text ?? This post was last edited by sz07551com at 14:01:05

Php text watermark

The php text watermark is made of imagettftext. how do I calculate the width and height of the text ??

 


Reply to discussion (solution)

If you do not consider the text rotation angle,

$width=strlen($text)*$font_size;$height=$font_size;

The above calculation only applies to the same width font. for details, see the imagettfbbox () function, which can solve your needs, including the angle.

Imagettfbbox -- get the text range using the TrueType font

Array imagettfbbox (float size, float angle, string fontfile, string text)
This function calculates and returns the pixel size of a virtual box surrounded by TrueType text ranges.
The font size in pixels.
Angle text will be measured in angle size.
The file name of the fontfile TrueType font file (which can be a URL ).
The string to be measured in text.

Imagettfbbox () returns an array containing eight units to indicate the four corners of the text box:
Position X in the lower left of 0
1 position Y in the lower left corner
2 position X in the lower right corner
3 position Y in the lower right corner
4. position X in the upper right corner
5. position Y in the upper right corner
6. position X in the upper left corner
7. position Y in the upper left corner
These vertices are irrelevant to the angle of the text. Therefore, the "upper left corner" indicates the upper left corner of the text when the text is viewed horizontally.

Imagettfbbox -- get the text range using the TrueType font

Array imagettfbbox (float size, float angle, string fontfile, string text)
This function calculates and returns the pixel size of a virtual box surrounded by TrueType text ranges.
The font size in pixels.
Angle text will be measured in angle size.
The file name of the fontfile TrueType font file (which can be a URL ).
The string to be measured in text.

Imagettfbbox () returns an array containing eight units to indicate the four corners of the text box:
Position X in the lower left of 0
1 position Y in the lower left corner
2 position X in the lower right corner
3 position Y in the lower right corner
4. position X in the upper right corner
5. position Y in the upper right corner
6. position X in the upper left corner
7. position Y in the upper left corner
These vertices are irrelevant to the angle of the text. Therefore, the "upper left corner" indicates the upper left corner of the text when the text is viewed horizontally.

I am not using any of the eight parameters,

Can I write a processing function? Thank you.

() Text)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.