2010-07-27 5 views

답변

1

나는 성공적으로 (썸네일) 이미지에 텍스트를 추가하려면이 코드를 사용했습니다 : : 또한 당신은 튜토리얼 링크

워터 마크으로 글꼴을 사용하도록 imagettftext() 기능을 사용할 수 있습니다

(주 그 글꼴을 제공해야합니다.)

function createImage($in_filename, $out_filename, $width, $height) 
{ 
    $src_img = ImageCreateFromJpeg($in_filename); 

    $old_x = ImageSX($src_img); 
    $old_y = ImageSY($src_img); 
    $dst_img = ImageCreateTrueColor($width, $height); 
    ImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $old_x, $old_y); 

    addWatermark($dst_img); 

    ImageJpeg($dst_img, $out_filename, 80); 

    ImageDestroy($dst_img); 
    ImageDestroy($src_img); 
} 

function addWatermark($image) 
{ 
    $text = "watermark text"; 

    $font = realpath($_SERVER["DOCUMENT_ROOT"] . "/code/COURBD.TTF"); // case sensitive 
    if ($font == false) return; 

    $fontSize = 11; 
    $borderOffset = 4; 

    $dimensions = ImageTtfBBox($fontSize, 0, $font, $text . "@"); 
    $lineWidth = ($dimensions[2] - $dimensions[0]); 

    $textX = (ImageSx($image) - $lineWidth)/2; 
    $textY = $borderOffset - $dimensions[7]; 

    $white = ImageColorAllocate($image, 240, 240, 240); 
    ImageTtfText($image, $fontSize, 0, $textX, $textY, $white, $font, $text); 
} 

의견 환영합니다.

관련 문제