PHP text watermark with Imagettftext do, how to calculate the width of the text of the high??

Source: Internet
Author: User
This post was last edited by sz07551com on 2013-06-28 14:01:05

PHP text watermark

PHP text watermark with Imagettftext do, how to calculate the width of the text of the high??

 
  


Reply to discussion (solution)

If the text rotation angle is not considered,

$width =strlen ($text) * $font _size; $height = $font _size;

The above calculation only applies to the equal width font, see: Imagettfbbox () function, it can solve your needs, including angle

Imagettfbbox--Gets the range of text using TrueType fonts

Array imagettfbbox (float size, float angle, st Ring Fontfile, string text)
This function calculates and returns the pixel size of a virtual box that surrounds the TrueType text range. The font size of the
size pixel unit. The size of the angle
angle text will be measured. The file name of the
fontfile TrueType font file (which can be a URL). The
text string to measure.

Imagettfbbox () returns an array of 8 cells representing four corners of the text box:
0 lower left x position
1 lower left corner y position
2 lower right x position
3 lower right corner y position
4 upper right X position
5 upper right Y position
6 upper left corner x position
7 upper left Y position
These points are relative to the text and are angle independent, so the upper left corner refers to the upper-left corner of the text when viewed horizontally.

Imagettfbbox--Get the range of text using TrueType fonts

Array Imagettfbbox (float size, float angle, string fontfile, string text)
This function calculates and returns the pixel size of a virtual box that surrounds the TrueType text range.
The font size of a size pixel unit.
Angle text will be measured by the angle size.
Fontfile the file name of the TrueType font file (which can be a URL).
The text string to measure.

Imagettfbbox () returns an array of 8 cells representing the four corners of the text outer frame:
0 lower left corner X position
1 lower left corner Y position
2 lower right corner X position
3 lower right corner Y position
4 upper right corner X position
5 upper right corner Y position
6 upper left corner X position
7 upper left corner Y position
These points are relative to the text and are independent of the angle, so the upper left corner refers to the upper-left corner of the text when viewed horizontally.

8 parameters, I do not how to use,

Can you write a handler function? Thank you

(6,7)   (4,5)     Text (0,1)   (2,3)
  • 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.