[請益] GD畫字問題

看板PHP作者 (水牛比爾)時間11年前 (2014/09/30 12:03), 編輯推噓1(107)
留言8則, 2人參與, 最新討論串1/1
這是我網站的gd_info(): http://miko.tw/~buffalobill/gdtest/gd_info.php 我寫了一個用GD載入思源字體畫字的程式: http://miko.tw/~buffalobill/gdtest/index.php 但是o的右邊會被吃掉 我不知道是哪邊出的問題 http://miko.tw/~buffalobill/gdtest/index.php?input=A "A"是沒問題的 http://miko.tw/~buffalobill/gdtest/index.php?input=R 但是R就會被吃掉 http://miko.tw/~buffalobill/gdtest/index.php?arial=on&input=R 換成arail字體也是一樣 以下是我的原始碼: 不知道是哪裡有算錯,還是其它資訊要判斷 <?php $point = 300; $pixel = $point * 72 / 96; //point size is 72 dpi, while GD is 96 dpi $font_file = './NotoSansCJKtc-Medium.otf'; //使用思源字體 if(ISSET($_REQUEST["arial"])){$font_file="arial.ttf";} $input = "Hello"; if(ISSET($_REQUEST["input"])){ $input = $_REQUEST["input"];} $bbox = imageftbbox($pixel, 0, $font_file, $input); $img_width = abs($bbox[2] - $bbox[0]); $img_height = abs($bbox[7] - $bbox[1]); $myimg = imagecreate($img_width, $img_height); $bg_colour = imagecolorallocate( $myimg, 255, 44, 44 ); $text_colour = imagecolorallocate( $myimg, 13, 12, 8 ); imagefilledrectangle($myimg, 0, 0, $img_width, $img_height, $bg_colour); $x = $bbox[6] * -1; $y = $bbox[7] * -1; imagefttext($myimg, $pixel, 0, $x, $y, $text_colour, $font_file, $input); header('Content-Type: image/png'); imagepng($myimg); imagedestroy($myimg); ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.148.94 ※ 文章網址: http://www.ptt.cc/bbs/PHP/M.1412049824.A.152.html

10/01 17:15, , 1F
http://goo.gl/59zgo1 這邊有相關的討論,不過最後的結論
10/01 17:15, 1F

10/01 17:16, , 2F
似乎是故意讓圖在寬度上變大,最後再切掉周空白 Orz
10/01 17:16, 2F

10/01 17:17, , 3F
周圍的空白 Orz 底下也有人找出 GD 的原始計算方式
10/01 17:17, 3F

10/01 17:18, , 4F
http://goo.gl/Vjdc3H 裡頭提到 "這方法取的是 control
10/01 17:18, 4F

10/01 17:19, , 5F
box, 近似於實際的外框, 但某些情況會比實際外框小"
10/01 17:19, 5F

10/02 13:48, , 6F
結果我讓圖變大再用imagecropauto,底下多一條黑線…
10/02 13:48, 6F

10/02 13:50, , 7F

10/02 13:51, , 8F
從一個bug跳到另一個bug...Orz
10/02 13:51, 8F
文章代碼(AID): #1KAYkW5I (PHP)
文章代碼(AID): #1KAYkW5I (PHP)