亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > PHP > 正文

php實現在限定的區域里自動調整字體大小的功能

2020-03-22 18:34:41
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了php實現在限定區域里自動調整字體大小的類,實例分析了php操作圖片及字體的技巧,具有一定參考借鑒價值,需要的朋友可以參考下

本文實例講述了php實現在限定區域里自動調整字體大小的類。具體如下:

 ?php// Image Fit Text Class 0.1 by ming0070913CLASS ImageFitText{ html' target='_blank'>public $font, $fontsize, $width, $height; public $step_wrap, $step_fontsize; public function __construct($font, $step_wrap=1, $step_fontsize=1){ $this- font = $font; $this- step_wrap = $step_wrap 1?$step_wrap:1; $this- step_fontsize = $step_fontsize 1?$step_fontsize:1; function fit($width, $height, $text, $fontsize, $min_fontsize=5, $min_wraplength=0){ $this- fontsize = $fontsize; $text_ = $text; while($this- TextHeight($text_) $height $fontsize $min_fontsize) $fontsize -= $this- step_fontsize; while(($this- TextWidth($text_) $width || $this- TextHeight($text_) $height) $fontsize $min_fontsize){ $fontsize -= $this- step_fontsize; $wraplength = $this- maxLen($text); $text_ = $text; while($this- TextWidth($text_) $width $wraplength =$min_wraplength+$this- step_wrap){ $wraplength -= $this- step_wrap; $text_ = wordwrap($text, $wraplength, /n , true); //To speed up: if($this- TextHeight($text_) $height) break; if($wraplength =$min_wraplength) break; $wraplength_ = $wraplength; $wraplength = ceil($wraplength/($this- TextWidth($text_)/$width)); $wraplength = $wraplength ($min_wraplength+$this- step_wrap)?($min_wraplength+$this- step_wrap):$wraplength; $this- width = $this- TextWidth($text_); $this- height = $this- TextHeight($text_); return array( fontsize = $fontsize, text = $text_, width = $this- width, height = $this- height); function maxLen($text){ $lines = explode( /n , str_replace( /r , , $text)); foreach($lines as $line) $t[] = strlen($line); return max($t); function TextWidth($text){ $t = imagettfbbox($this- fontsize, 0, $this- font, $text); return $t[2]-$t[0]; function TextHeight($text){ $t = imagettfbbox($this- fontsize, 0, $this- font, $text); return $t[1]-$t[7];? 

使用范例如下:

 ?php// Image Fit Text Class 0.1 by ming0070913// Example Fileinclude imagefittext.class.php // Settings :// The text$text = PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works, try the introductory tutorial. After that, check out the online manual. // The maximun width$width = 200;// The maximun height$height = 100;// Position of the text and the box$x1 = 50;$y1 = 50;// The starting font size$fontsize = 10;// The minimun font size. The script will stop if it cannot fit the text even with this size.$min_fontsize = 3;// The minimun wrap length for each line. The script will try another font size if it cannot fit the text even with this wrap length.$min_wraplength = 0;// The font$font = arial.ttf // The space between the box and the text. It s independent to the script which can be ignored$padding = 3;// If the script cannot fit the text for certain wrap length, it will try the wrap length again with the reduction in this value.// It reduce the accuracy, but will slightly speed up the process.$step_wrap = 1;// If the script cannot fit the text for certain font size, it will try the the font size again with the reduction in this value.// It reduce the accuracy, but will slightly speed up the process.$step_fontsize = 1;// Create a image$im = @imagecreatetruecolor($width+$x1*2, $height+$y1*2+80) or die( Cannot Initialize new GD image stream // Start the timer$time_start = microtime_float();// The class$imagefittext = new ImageFitText($font, $step_wrap, $step_fontsize);// Fit the text// It returns the result in a array with fontsize , text , width , height $fit = $imagefittext- fit($width-$padding*2, $height-$padding*2, $text, $fontsize, $min_fontsize, $min_wraplength);// Stop the timer$time = round(microtime_float()-$time_start, 3);$white = imagecolorallocate($im, 255, 255, 255);// Draw a boximagerectangle($im, $x1, $y1, $x1+$width, $y1+$height, $white);// Write the text +8 because the text will move up originallyimagettftext($im, $fit[ fontsize ], 0, $x1+$padding, $y1+$padding+8, $white, $font, $fit[ text // Print some info. about the textimagestring($im, 5, $x1, $y1+$height+30, Fontsize : .$fit[ fontsize ], $white);imagestring($im, 5, $x1, $y1+$height+45, Text Size : .$fit[ width ]. x .$fit[ height ], $white);imagestring($im, 5, $x1, $y1+$height+60, Box Size : .($width-$padding*2). x .($height-$padding*2), $white);imagestring($im, 5, $x1, $y1+$height+75, Time used : .$time. s , $white);// Print the imageheader ( Content-Type: image/png imagepng($im);imagedestroy($im);function microtime_float(){ // Timer list($usec, $sec) = explode( , microtime()); return ((float)$usec + (float)$sec);? 

總結:以上就是本篇文的全部內容,希望能對大家的學習有所幫助。

相關推薦:

php實現新聞發布系統

PHP讀取配置文件類實例

php生成縮略圖的方法

以上就是php實現在限定的區域里自動調整字體大小的功能的詳細內容,PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
色婷婷综合久久久久中文字幕1| 亚洲一区二区国产| 亚洲欧美另类国产| 九色精品美女在线| 久久不射电影网| 亚洲视频在线观看视频| 日韩av电影在线免费播放| 日韩亚洲第一页| 国产精品青青在线观看爽香蕉| 久久久最新网址| 国产福利视频一区二区| 精品国产乱码久久久久久天美| 91亚洲一区精品| 欧美中文在线观看国产| 动漫精品一区二区| 亚洲日韩中文字幕| 国产精品爽爽爽爽爽爽在线观看| 在线视频国产日韩| 亚洲大胆人体在线| 日韩有码片在线观看| 欧美日韩第一视频| 97精品国产91久久久久久| 亚洲人成网站在线播| 日本久久久久久| 欧美三级欧美成人高清www| 欧美日韩aaaa| 68精品久久久久久欧美| 久久男人资源视频| 日韩精品一区二区三区第95| 日韩在线精品一区| 欧美一级高清免费| 中文字幕在线看视频国产欧美在线看完整| 精品国产欧美一区二区五十路| 亚洲偷欧美偷国内偷| 欧美猛男性生活免费| 日韩av在线资源| 成人在线中文字幕| 精品伊人久久97| 国模视频一区二区三区| 国产91精品青草社区| 91久久精品在线| 欧美成人一二三| 国产经典一区二区| 亚洲人成在线观看网站高清| 亚洲深夜福利在线| 亚洲欧美国产高清va在线播| 国产成人精品免费久久久久| 亚洲高清一区二| 国产精品极品在线| 国产成人免费av电影| 国产亚洲欧洲高清一区| 国产在线久久久| 午夜精品视频在线| 国产精品中文久久久久久久| 国产有码在线一区二区视频| 另类专区欧美制服同性| 日韩av电影中文字幕| 91中文字幕在线观看| 欧美最顶级丰满的aⅴ艳星| 亚洲欧美国产日韩中文字幕| 亚洲高清福利视频| 奇米成人av国产一区二区三区| 精品成人av一区| 亚洲毛片一区二区| 2018日韩中文字幕| 中文字幕无线精品亚洲乱码一区| 高清亚洲成在人网站天堂| 久久精品一偷一偷国产| 欧美一性一乱一交一视频| 日本a级片电影一区二区| 日本最新高清不卡中文字幕| 日韩h在线观看| 97久久国产精品| 日韩在线播放视频| 欧美成年人在线观看| 91精品久久久久久久久青青| 日韩av网址在线| 亚洲石原莉奈一区二区在线观看| 色黄久久久久久| 亚洲精品av在线| 中文字幕精品网| 亚洲最新av在线网站| 亚洲国产精品热久久| 亚洲精品国产精品国自产在线| 久久99热精品这里久久精品| 日韩国产在线播放| 久久久国产精品免费| 日韩电影免费观看在线| 欧美成人黄色小视频| 亚洲美女www午夜| 国产日本欧美在线观看| 色婷婷**av毛片一区| 性欧美办公室18xxxxhd| 久久久亚洲国产天美传媒修理工| 日本久久91av| 欧洲成人在线观看| 国产精品亚洲综合天堂夜夜| 欧美自拍大量在线观看| 欧美一区二粉嫩精品国产一线天| 日本在线精品视频| 久久精品国产欧美激情| 日韩美女av在线| www.日韩视频| 亚洲最新av网址| 日韩免费不卡av| 亚洲男人天堂视频| 原创国产精品91| 最近2019中文字幕mv免费看| 欧美自拍大量在线观看| 国产精品青青在线观看爽香蕉| 亚洲精品狠狠操| 成人激情视频免费在线| 亚洲一区二区三区视频播放| 国产成人精品a视频一区www| 在线成人激情视频| 国产精国产精品| 91性高湖久久久久久久久_久久99| 国产精品久久久久久久久久ktv| 国产精品网址在线| 中文字幕在线看视频国产欧美在线看完整| 欧美一区二区视频97| 91美女福利视频高清| 色婷婷久久一区二区| 国产女人精品视频| 国产精品免费看久久久香蕉| 亚洲国产精品嫩草影院久久| 精品丝袜一区二区三区| 久久精品一本久久99精品| 亚洲香蕉伊综合在人在线视看| 另类视频在线观看| 日韩av大片在线| 黑人巨大精品欧美一区二区三区| 精品中文字幕在线2019| 国产九九精品视频| 国产精品直播网红| 中文字幕日韩av综合精品| 4p变态网欧美系列| 亚洲欧美另类在线观看| 在线观看国产精品淫| 一色桃子一区二区| 日韩高清电影好看的电视剧电影| 97精品一区二区视频在线观看| 精品久久久久久久久久久久久久| 亚洲精品国产综合久久| 中文字幕精品国产| 91中文字幕一区| 欧美另类极品videosbestfree| 美女扒开尿口让男人操亚洲视频网站| 91欧美日韩一区| 91精品视频免费看| 成人黄色av免费在线观看| 日韩在线欧美在线| 欧美日韩国产va另类| 国产精品久久久av久久久| 粉嫩av一区二区三区免费野| 日韩激情视频在线播放| 亚洲男人天堂2024| 日韩中文理论片| 欧美尺度大的性做爰视频| 亚洲第一精品电影| 国产精品久久久久久一区二区| 国产精品电影在线观看| 久久久久久久国产| 国产在线不卡精品|