2014-01-19 3 views
0

imagettftext()을 사용하여 PHP를 통해 이미지에 텍스트를 추가하려고합니다. 지금까지 약 6 개의 다른 자습서를 통해 작동하도록 시도했으며 성공하지 못했습니다. 현재 PHP 문서 페이지에서이 코드를 시도하고 있습니다.imagettftext는 작동하지 않습니다. 텍스트가 표시되지 않습니다

<?php 
// 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); 
?> 

그러나 아무것도 표시되지 않습니다. GD 라이브러리를 설치하고 freetype을 활성화했습니다. PHP 파일과 동일한 디렉토리에 arial.ttf이 있는데 왜 작동하지 않는지 알 수 없습니다. 내가 얻는 것은 빈 이미지뿐입니다.

EDIT : "[19-Jan-2014 16:31:07] PHP 경고 : imagettftext() : /var/www/php/bb/test.php에서 글꼴을 찾지 못했습니다. on line 21 "

+0

파일에 오류를 기록하고, 여기에'보기 위해서는 ini_set ("log_errors 옵션을", 1)을 게시하시기 바랍니다; ini_set ("error_log", "php-error.log");'스크립트와 동일한 디렉토리에서'php-error.log' 파일을 생성하고 쓰기 권한을 부여하는 것을 잊지 마십시오. –

+0

"[19-Jan-2014 16:31:07] PHP 경고 : imagettftext() : 21 행의 /var/www/php/bb/test.php에서 글꼴을 찾지 못했거나 열 수 없었습니다. [19 -Jan-2014 16:31:08] ". 나는 분명히 같은 디렉토리에 arial.ttf를 가지고 있는데 왜 그런 일이 일어나는지 확신 할 수 없다. –

+0

나는 정확한 코드와 그 작업을 테스트했다. –

답변

0

나는 상대 경로 대신 ttf의 실제 경로를 입력하려고했다.

putenv('GDFONTPATH=' . realpath('.')); 

또는

$font = '/home/user/arial.ttf'; 
관련 문제