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

首頁 > 編程 > PHP > 正文

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

2020-03-22 17:33:39
字體:
來源:轉載
供稿:網友
本文實例講述了php實現在限定區域里自動調整字體大小的類。分享給大家供大家參考。具體如下:這里的php類imagefittext.html' target='_blank'>class.php實現在限定的區域里自動調整字體大小的功能。
// Image Fit Text Class 0.1 by ming0070913CLASS ImageFitText{ 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]; 使用范例如下:// 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教程

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品久久久久久久久粉嫩av| 激情亚洲一区二区三区四区| 欧美人与物videos| 国产精品免费一区二区三区都可以| 国产精品视频午夜| 91精品在线播放| 午夜精品久久久久久久99热浪潮| 亚洲va久久久噜噜噜久久天堂| 国产福利精品av综合导导航| 91久久精品一区| 欧美激情一区二区三区成人| 色妞色视频一区二区三区四区| 精品久久久久久久久久久久久久| 成人亚洲激情网| 日韩中文字幕在线免费观看| 91在线观看免费观看| 中文字幕v亚洲ⅴv天堂| 国产99久久精品一区二区| 国产一区二区欧美日韩| 久久国产精品影片| 亚洲а∨天堂久久精品9966| 91网在线免费观看| 精品国产91久久久久久| 91手机视频在线观看| 高清一区二区三区日本久| 在线亚洲男人天堂| 尤物yw午夜国产精品视频| 97精品在线视频| 色综合久久久久久中文网| 成人a视频在线观看| 亚洲第一区第二区| 国产精品视频播放| 亚洲激情久久久| 热久久免费视频精品| 久久久人成影片一区二区三区| 欧美激情视频网站| 欧美在线精品免播放器视频| 午夜剧场成人观在线视频免费观看| 亚洲一区二区三区香蕉| 日韩中文字幕亚洲| 日韩中文字幕网站| 疯狂做受xxxx高潮欧美日本| 亲子乱一区二区三区电影| 91精品国产免费久久久久久| 精品久久久在线观看| 97视频在线免费观看| 91久久久国产精品| 最近2019年中文视频免费在线观看| 国产精品户外野外| 久久久精品欧美| 国产乱肥老妇国产一区二| 欧美激情一区二区三区高清视频| 欧美激情极品视频| 亚洲区中文字幕| 欧美猛男性生活免费| 日韩精品www| 亚洲一品av免费观看| 91在线免费看网站| 亚洲国产天堂久久综合网| 中文字幕av一区中文字幕天堂| 最近2019中文字幕在线高清| 国产精品第三页| 国产精品白嫩美女在线观看| 精品久久久久久久大神国产| 久久久之久亚州精品露出| 久久福利视频网| 亚洲欧美三级伦理| 国产亚洲精品一区二区| 亚洲免费av电影| 91精品久久久久久久久久久久久| 国产日韩av在线播放| 91久久久久久久久久| 久久亚洲精品小早川怜子66| 91av在线看| 欧美精品国产精品日韩精品| 国产精品极品美女粉嫩高清在线| 欧美视频在线看| zzijzzij亚洲日本成熟少妇| 国语自产精品视频在免费| 午夜伦理精品一区| 欧美性受xxx| 亚洲第一页中文字幕| 亚洲国产另类 国产精品国产免费| 亚洲精选一区二区| 亚洲成人1234| 91超碰caoporn97人人| 欧美激情一区二区三级高清视频| 国产精品久久久久免费a∨大胸| 日韩欧美亚洲国产一区| 国产日韩欧美影视| 亚洲成人久久网| 欧美精品www| 日本精品久久久久影院| 欧美精品在线网站| 精品久久香蕉国产线看观看gif| 久久精品电影一区二区| 国产日韩欧美影视| 国产一区二区三区中文| 亚洲一区二区三区久久| 国产精品美女视频网站| 欧美一级视频免费在线观看| 国产69精品久久久| 色综合老司机第九色激情| 亚洲国产小视频| 77777少妇光屁股久久一区| 欧美最猛性xxxxx(亚洲精品)| 国产成人福利视频| 亚洲tv在线观看| 欧美专区福利在线| 日韩专区在线播放| 亚洲偷熟乱区亚洲香蕉av| 亚洲精品国产精品国自产在线| 亚洲国产精品电影| 国产精品免费小视频| 欧美精品aaa| 大桥未久av一区二区三区| 日韩av免费在线观看| 欧美电影在线播放| 日韩在线激情视频| 国产精品视频地址| 国产主播欧美精品| 亚洲国产欧美一区| 精品偷拍一区二区三区在线看| 日韩精品在线观看视频| 欧美精品videosex牲欧美| 日韩免费观看在线观看| 亚洲裸体xxxx| 91精品国产综合久久香蕉的用户体验| 中文字幕亚洲激情| 亚洲网在线观看| 在线观看久久久久久| 国产日韩在线视频| 亚洲精品日产aⅴ| 国产亚洲欧美一区| 国产精品一区二区在线| 久久国产一区二区三区| 高清欧美一区二区三区| 日韩欧美精品网址| 国产成人97精品免费看片| 国产免费久久av| 日韩av一区二区在线观看| 91美女片黄在线观看游戏| 国产视频精品在线| 国产日韩av高清| 欧美壮男野外gaytube| 欧美精品一区二区三区国产精品| 亚洲国产欧美一区| 亚洲第一中文字幕在线观看| 日韩少妇与小伙激情| 国产大片精品免费永久看nba| 7777kkkk成人观看| 国产精品揄拍500视频| 精品国内亚洲在观看18黄| 欧美性生活大片免费观看网址| 91久久在线观看| 中文字幕视频在线免费欧美日韩综合在线看| 国产精品丝袜一区二区三区| 国产精品av在线| 国产成人一区二区在线| 国产精品高清免费在线观看| 91欧美激情另类亚洲| 中文字幕欧美精品日韩中文字幕| 久久中文精品视频| 日韩大陆欧美高清视频区|