PHP php문서를 이미지화 하기

2012.02.07 13:13

juro 조회 수:605

<PHP
$im = imagecreate(300, 100);  
  
$bg = imagecolorallocate($im, 204, 204, 204);  
$textcolor = imagecolorallocate($im, 0, 0, 255);  

function imagestringcutted($img,$font,$y,$x1,$x2,$text,$color,$align="center") {  
    $fontwidth = imagefontwidth($font);  
    $fullwidth = strlen($text) * $fontwidth;  
    $maxwidth = $x2-$x1;  
    $targetwidth = $fullwidth-(4*$fontwidth);  
    if($fullwidth > $maxwidth) {  
        for($i = 0; $i < strlen($text) AND ((strlen($text)-($i-4))*$fontwidth) > $targetwidth ;$i++) { }  
        $text = substr($text,0,(strlen($text)-$i)-4)."...";  
    }  
        
    if($align == "left") imagestring($img,$font,$x1,$y,$text,$color);  
    elseif($align == "right") imagestring($img,$font,$x2 - ((strlen($text) * $fontwidth)),$y,$text,$color);  
    else imagestring($img,$font,($x2-$x1)/ 2 - strlen($text) * $fontwidth / 2,$y,$text,$color);  
}
//font경로 설정
$font =  "C:/Windows/Fonts/gulim.ttc";
//utf로 설정하기
$text_type =         mb_convert_encoding("Test아아아아아아아아아", "UTF-8", "EUC-KR");
//imagestringcutted($im,6,50,50,300,"아아아아아아아아아",$textcolor,"center");  
//텍스트 출력하기
imagettftext($im , 10 , 0 , 10 , 50 , $textcolor ,$font , $text_type);

header("Content-type: image/png");  

imagepng($im);  
>

© juroweb 2003-2014. All rights reserved
log in