Используя пример с php.net, я получаю предупреждение, а изображение не отрисовывается правильно. Я указываю полный путь к файлу .ttf следующим образом: /var/www/public/myfont.ttf
PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in <phpfile>
Я использую собственный шрифт .ttf, который можно найти здесь. Я могу нормально открыть файл в Ubuntu как допустимый файл шрифта. Я также пробовал другие шрифты, с тем же результатом.
Я использую 32-разрядную версию Ubuntu 10.04 LTS с установленными apache2, php5, freetype6 и php5-gd. Я также попытался chmod 777 файл и папку с файлом ttf с тем же результатом.
Как я могу заставить пример работать с использованием пользовательского файла шрифта ttf?
* Изменить: код, который я использую:
<?php
// File is: /var/www/public/test.php
// Apart from $font variable, it's copy-pasted from php.net
// Set the content-type
header('Content-Type: image/png');
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = '/var/www/public/UnmaskedBB.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
Вывод из phpinfo();
[gd]
GD Support enabled
GD Version 2.0
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.11
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.42
WBMP Support enabled
Тестирование is_file
и is_readable
:
$font = realpath('./').'/UnmaskedBB.ttf';
echo "Font: ".$font; // /var/www/public/UnmaskedBB.ttf
echo "Is file? ".is_file($font); // 1
echo "Is readable? ".is_readable($font); // 1
tff
- person Pekka   schedule 22.05.2011wmt
, при этом PHPThumb проверял, что файл шрифта существует и может быть прочитан перед вызовом imagettftext. Я мог бы добавить, что imagettfbox выдает ту же ошибку. Есть ли другой хороший способ отладить то, что здесь происходит? - person Jon Skarpeteig   schedule 22.05.2011is_readable()
илиis_file()
? - person Pekka   schedule 22.05.2011Arial.ttf
? - person Pekka   schedule 22.05.2011