2012-08-05 2 views
1

내 captcha에 대해 다음 코드가 있습니다. 이미지의 행은 생성되지만 4 자리 숫자는 표시되지 않습니다. 거기에 몇 가지 문제가 있다고 가정합니다.imagettftext 함수가 PHP에서 작동하지 않습니다

imagettftext ($ image, $ font_size, 0,15,30, $ text_color, 'font.TTF', $ text);

코드 기능. $ _server [ 'DOCUMENT_ROOT'];를 사용하여 글꼴 파일 경로를 설정하려고했습니다. 아직 작동하지 않았다.

여기에 코드입니다 : 코드 아래

 <?php 
    session_start(); 
    header('Content-type: image/jpeg'); 

    $text= $_SESSION['secure']; 

    $font_size =30; 
    $image_width= 110; 
    $image_height=40; 

    $image=imagecreate($image_width,$image_height); 
    imagecolorallocate($image, 255, 255, 255); 
    $text_color = imagecolorallocate($image, 0, 0, 0); 


    for($x=1; $x<=30; $x++){ 
     $x1 = rand(1,100); 
     $x2 = rand(1,100); 
     $y1 = rand(1,100); 
     $y2 = rand(1,100); 
    imageline($image, $x1, $x2, $y1, $y2, $text_color); 
    } 

    imagettftext($image,$font_size,0,15,30,$text_color,'font.TTF',$text); 
    imagejpeg($image); 
    ?> 

답변

1

이 완벽하게 내 PC

정확해야 글꼴 경로를 기억에서 작업. enter image description here

<?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); 
+0

미안 해요, 난 당신이 실제로 말을 하려는지 이해하지 못했다 출력 -

? – user1460822

+0

이 URL 참조 http://stackoverflow.com/questions/8496809/why-isnt-the-php-imagettftext-function-working-in-this-case –

+0

url을 모두 참조하십시오 http://stackoverflow.com/questions/ 7034698/imagettftext-not-working –