简体   繁体   中英

imagettftext doesn't output anything

I'm using the basic example from php.net on my local machine (Macbook Pro w/ Snow Leopard) to display a line of text using the GD library, but nothing is showing for me. I have display errors turned on and I double checked that the GD library and the FreeType library is being used, but I continue to get blank white pages. Here's the code I'm testing, taken directly from http://php.net/manual/en/function.imagettftext.php

I supsect it's the 'arial.ttf' part that's causing problems. Any way for me to test that? I figured a default install would surely have that available.

// 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 = 'arial.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);

Here's my PHP info for GD:

GD Support  enabled
GD Version  bundled (2.0.34 compatible)
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.4.4
GIF Read Support    enabled
GIF Create Support  enabled
JPEG Support    enabled
libJPEG Version 8
PNG Support enabled
libPNG Version  1.5.2
WBMP Support    enabled
XBM Support enabled

The font file "arial.ttf" is not provided with PHP by default.

Your script requires access to the font file in order to use it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM