我有以下代碼以在圖像上打印文本。我還在文本週圍添加了一個調試框。不過,我注意到左邊的文字位於PHP給我的框外imagettfbbox
。如何使用PHP和GD帳戶進行字體刷新
這看起來與字體斜的問題。無論如何說明這一點?我可以計算出從斜槓開始到實際位置imagettfbbox
給我的距離嗎?
我不認爲這是字體的問題,因爲我嘗試了幾個腳本樣式字體,結果是相似的。
<?php
$font = 'scriptin.ttf';
$text = 'Ipsum';
$size = 30;
$image = imagecreatetruecolor(200, 200);
$fontColour = imagecolorallocate($image, hexdec('11'), hexdec('11'), hexdec('11'));
$bgColour = imagecolorallocate($image, hexdec('CC'), hexdec('CC'), hexdec('CC'));
imagefilledrectangle($image, 0, 0, 200, 200, $bgColour);
$dimensions = imagettfbbox($size, 0, $font, $text);
imagefilledrectangle(
$image,
$dimensions[0] + 40,
$dimensions[7] + 50,
$dimensions[2] + 40,
$dimensions[3] + 50,
imagecolorallocate($image, mt_rand(1, 180), mt_rand(1, 180), mt_rand(1, 180))
);
imagettftext(
$image,
$size,
0,
40,
50,
$fontColour,
$font,
$text
);
header('Content-Type: image/png');
imagepng($image);
的代碼和字體可以在這裏找到:https://github.com/AydinHassan/image-swash-example
如果您在存儲庫點了VHOST,你可以打swash.php
看起來您沒有正確放置方框着色:左側的「缺失」空間量看起來與右側的「太多」空間量相同。 –
這就是我的想法,但如果我是這樣,我不明白我在哪裏做錯了。我正在使用信息'imagettfbbox'給我。 –
http://php.net/manual/en/function.imagettfbbox.php#97211表明這是一個已知的,如果不方便的話。 –