這篇文章主要介紹了PHP獲取一段文本顯示點陣寬度和高度的方法,涉及imagettfbbox函數的用法及php操作ttf文字的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了PHP獲取一段文本顯示點陣寬度和高度的方法。分享給大家供大家參考。具體如下:
- define("F_SIZE", 8);
- define("F_FONT", "arial.ttf");
- function get_bbox($text){
- return imagettfbbox(F_SIZE, 0, F_FONT, $text);
- }
- function text_height ($text) {
- $box = get_bbox($text);
- $height = $box[3] - $box[5];
- return $height;
- }
- function text_width ($text) {
- $box = get_bbox($text);
- $width = $box[4] - $box[6];
- return $width;
- }
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答