作者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/cn.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