作者buffalobill (水牛比爾)
看板PHP
標題[請益] GD畫字問題
時間Tue Sep 30 12:03:42 2014
這是我網站的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://webptt.com/m.aspx?n=bbs/PHP/M.1412049824.A.152.html
2F:→ hit1205: 似乎是故意讓圖在寬度上變大,最後再切掉周空白 Orz 10/01 17:16
3F:→ hit1205: 周圍的空白 Orz 底下也有人找出 GD 的原始計算方式 10/01 17:17
5F:→ hit1205: box, 近似於實際的外框, 但某些情況會比實際外框小" 10/01 17:19
6F:→ buffalobill: 結果我讓圖變大再用imagecropauto,底下多一條黑線… 10/02 13:48
8F:→ buffalobill: 從一個bug跳到另一個bug...Orz 10/02 13:51