Al utilizar el example from php.net aparece una advertencia y la imagen no se muestra correctamente. Puedo proporcionar una ruta completa al archivo .ttf, así: /var/www/public/myfont.ttf
imagettftext no se puede abrir el archivo de fuente
PHP Warning: imagettftext() [<a href='function.imagettftext'>function.imagettftext</a>]: Could not find/open font in <phpfile>
estoy usando una costumbre .ttf fuente encontró here. Puedo abrir bien el archivo en Ubuntu como un archivo de fuente válido. También intenté otras fuentes, con el mismo resultado.
Estoy usando Ubuntu 10.04 LTS 32 bit, con apache2, php5, freetype6 y php5-gd instalados. También intenté chmod 777 archivo y carpeta con el archivo ttf, con el mismo resultado.
¿Cómo puedo obtener el ejemplo trabajando con un archivo de fuentes ttf personalizado?
* Editar: El código que estoy usando:
<?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);
?>
salida de 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
Prueba is_file
y 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
¿Puedes mostrar el código exacto? No puedo ver nada mal, pero por el bien de la integridad –
¿Estás 100% seguro de que es la ruta exacta de la fuente? ¿Teniendo en cuenta la sensibilidad de caso? –
Y parece que hay un error tipográfico: 'tff' –