看板 PHP 關於我們 聯絡資訊
各位前輩大家好,想請教一下,我用GD的imagettfbbox()產出字轉圖 (圖尺寸需跟字一樣大) 只要寬一點的字體,文字的右邊都會被裁到,是X軸沒抓準還是width沒抓準? 請問有其他解決的辦法嗎? PS.因主機不夠好,不能使用imagick處理,因為需好幾秒才會產出圖 為顧及速度,請問有能用GD解決的方式,或是有其他模組件可使用嗎? 懇請解惑,附上程式碼及裁到右邊的字圖 https://www.flickr.com/photos/57332716@N03/15371483427/in/photostream/player/ 謝謝 <?php //計算字的畫框大小 function textBox($size ,$file ,$string){ $rect= imagettfbbox( $size, 0, $file, $string ); $minX = min(array($rect[0],$rect[2],$rect[4],$rect[6])); $maxX = max(array($rect[0],$rect[2],$rect[4],$rect[6])); $minY = min(array($rect[1],$rect[3],$rect[5],$rect[7])); $maxY = max(array($rect[1],$rect[3],$rect[5],$rect[7])); return array( "left" => abs($minX), "top" => abs($minY), "width" => $maxX - $minX, "height" => $maxY - $minY, "box" => $rect ); } $size = 52; $file = 'font/arial.ttf'; $string = "M"; $box = textBox($size ,$file ,$string); $im= imagecreatetruecolor( $box['width'], $box['height'] ); $black = ImageColorAllocate ($im,255, 255, 255); $fill= imagefill( $im, 0, 0, $black ); $fcolor= imagecolorallocate( $im, 0, 0, 0); imagettftext( $im, $size, 0, 0, $box['top'], $fcolor, $file, $string ); header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.133.57.19 ※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1413566952.A.D84.html
hit1205: 感覺跟 #1KAYkW5I 是一樣的情形? 10/18 02:08
max701218: 網址失效,請問那篇有寫解決方法嗎? 10/18 15:21
hom1130: 一樓那是文章代碼,#1KAYkW5I還在 10/18 16:50
max701218: hom1130 謝謝提醒,我不太懂操作,找到文章了 10/19 21:54
max701218: hit1205 從你上一篇文章的回答找到答案,已解決 感謝 10/19 21:59