2014-07-24 3 views
3

2 줄의 텍스트를 추가하려고합니다. 한 사람의 이름을위한 것이고 다른 하나는 씨족의 이름입니다.이미지에 텍스트를 추가하려고합니다.

내가 잘못하고있는 것을 도울 수 있습니까? 나는 어떤 에러 메시지 나 아무것도 얻지 않으며 이미지는 잘로드 중이다. 저를 도와 주셔서

//Ribbons Image 
$ribbons = array(
    "ribbons/1STAID.png", 
    "ribbons/BMT.png", 
    "ribbons/BRA1A.png", 
    "ribbons/CCMD.png", 
    "ribbons/CCMDV2.png", 
    "ribbons/donator.png", 
    "ribbons/FTR.png", 
    "ribbons/GC.png", 
    "ribbons/GRA1A.png", 
    "ribbons/IOTP.png", 
    "ribbons/MEDIC.png", 
    "ribbons/PHA1A.png", 
    "ribbons/PILOT.png", 
    "ribbons/RCT1A.png", 
    "ribbons/RCT2A.png", 
    "ribbons/RCT3A.png", 
    "ribbons/RCT4A.png", 
    "ribbons/SRA1A.png", 
    "ribbons/SVR1A.png", 
    "ribbons/SVR2A.png", 
    "ribbons/SVR3A.png", 
    "ribbons/SVR4A.png", 
    "ribbons/SVR-ALTIS.png", 
    "ribbons/XOCMD.png", 
    "ribbons/XOCMDV2.png"); 


//Rank Image 
$rank = imagecreatefrompng("rank/2LT.png"); 

//Background 
$frame = imagecreatefrompng("sign3.png"); 

//imagecopymergy(output,image,x,y,0,0,w,h,100) 

//Adding rank 
imagecopymerge($frame, $rank, 30, 30, 0, 0, 10, 25, 100); 


//Trying to add the text on the image 
$im = imagecreatetruecolor(400, 30); 
$white = imagecolorallocate($im, 0, 0, 0); 
imagefilledrectangle($im, 0, 0, 399, 29, $white); 
$text = 'Test...'; 
$font = 'arial.ttf'; 
imagettftext($im, 20, 0, 10, 20, $white, $font, $text); 




//Adding the ribbon on the image 
$z = 0; 
$i = 0; 
for ($y = 0; $y <= 120; $y += 20) { 
    $z++; 
    for ($x = 0; $x <= 150; $x += 50) { 
     if ($i <= 24) { 
      $rib = imagecreatefromjpeg($ribbons[$i]); 
      imagecopymerge($frame, $rib, $x + 375, $y + 50, 0, 0, 50, 20, 100); 
     } 
     $i++; 
    } 
} 

//Save the image + Display 
imagepng($frame, 'generate/test.png'); 
imagepng($frame); 
header('Content-Type: image/png'); 

감사 :

이 내 코드입니다!

+0

당신은 당신의'$ font'에 액세스 할 수 있는지 확실합니까? – Darren

+0

내 서버에 arial.ttf가 있습니다. 나는 어떤 오류도 내지 않는다. –

+0

그래,'arial.ttf' 파일이 스크립트를 실행하려고하는 디렉토리와 같은 디렉토리에 있습니까? – Darren

답변

0

근무 코드 :

//Ribbons Image 
$ribbons = array(
    "ribbons/1STAID.png", 
    "ribbons/BMT.png", 
    "ribbons/BRA1A.png", 
    "ribbons/CCMD.png", 
    "ribbons/CCMDV2.png", 
    "ribbons/donator.png", 
    "ribbons/FTR.png", 
    "ribbons/GC.png", 
    "ribbons/GRA1A.png", 
    "ribbons/IOTP.png", 
    "ribbons/MEDIC.png", 
    "ribbons/PHA1A.png", 
    "ribbons/PILOT.png", 
    "ribbons/RCT1A.png", 
    "ribbons/RCT2A.png", 
    "ribbons/RCT3A.png", 
    "ribbons/RCT4A.png", 
    "ribbons/SRA1A.png", 
    "ribbons/SVR1A.png", 
    "ribbons/SVR2A.png", 
    "ribbons/SVR3A.png", 
    "ribbons/SVR4A.png", 
    "ribbons/SVR-ALTIS.png", 
    "ribbons/XOCMD.png", 
    "ribbons/XOCMDV2.png"); 


//Rank Image 
$rank = imagecreatefrompng("rank/2LT.png"); 

//Background 
$frame = imagecreatefrompng("sign3.png"); 

//imagecopymergy(output,image,x,y,0,0,w,h,100) 

//Adding rank 
imagecopymerge($frame, $rank, 30, 30, 0, 0, 10, 25, 100); 


//Trying to add the text on the image 
$im = imagecreatetruecolor(50, 30); 
$black = imagecolorallocate($im, 0, 0, 0); 
$white = imagecolorallocate($im, 0, 82, 255); 
imagefilledrectangle($im, 4, 4, 50, 25, $white); 
$text = 'Nato Military Corp'; 
$font = 'arial.ttf'; 

imagettftext($frame, 12, 0, 450, 220, $white, $font, $text); 
//imagecopymerge($frame, $im, 10, 20, 0, 0, 10, 25, 100); 


//Adding the ribbon on the image 
$z = 0; 
$i = 0; 
for ($y = 0; $y <= 120; $y += 20) { 
    $z++; 
    for ($x = 0; $x <= 150; $x += 50) { 
     if ($i <= 24) { 
      $rib = imagecreatefromjpeg($ribbons[$i]); 
      imagecopymerge($frame, $rib, $x + 375, $y + 50, 0, 0, 50, 20, 100); 
     } 
     $i++; 
    } 
} 

//Save the image + Display 
imagepng($frame, 'generate/test.png'); 
imagepng($frame); 
header('Content-Type: image/png'); 
관련 문제