前段时间我做了一个脚本,它接受一些文本并将其作为图像返回,并且工作完美。但我不确定从什么时候开始出现一个奇怪的错误。左边有一个(我向字体极客道歉)“字形”的字母被推到右边,所以字母开始在它上面,但只为主要字母留出空间,呵呵,我认为应该做一个例子。
(来源:esbasura.com)
预期结果是:(
来源:esbasura.com)
显然,“坏”的脚本是由我的脚本生成的,位于:http: //www.esbasura.com/images/text.php?txt= The%20quick%20brown%20fox%20jumps%20over%20the%20lazy %20dog.&fnt=1&size=23&bg=lightgrey 好的是 dafont 在这里生成的:http: //img.dafont.com/preview.php ?text=The%20quick%20brown%20fox%20jumps%20over%20the% 20lazy%20dog.&ttf=bleeding_cowboys0&ext=1&size=23&psize=m&y=46
我没有在脚本中做任何花哨的事情,这是相关部分:
imagefilledrectangle($im, 0, 0, $width, $height, $$bg);
imagettftext($im, $size, 0, (-1*$textsize[6]), (-1*$textsize[7]), $$color, $font, $text);
// imagefttext($im, $size, 0, (-1*$textsize[6]), (-1*$textsize[7]), $$color, $font, $text); same results using imagefttext
imagecolortransparent($im, $$bg);
header("Cache-Control: public"); // HTTP/1.1
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
我有点惊讶,因为,正如我所说,它曾经完美无瑕地工作。也许我的主人改变了我的机器。
(这是我的 phpinfo:http ://www.work4bandwidth.com/info.php )相关位:
gd
GD Support enabled
GD Version bundled (2.0.34 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.2.1
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled
编辑:另请注意,图像大小计算显然是在考虑字体的正确渲染后完成的,我正在使用以下方法进行计算:
$textsize = imagettfbbox($size, 0, $font, $text);
$width = ($textsize[2] - $textsize[0]);
$height = ($textsize[3] - $textsize[5]);