2010-07-27 7 views

Répondre

1

Je l'ai utilisé avec succès ce code pour ajouter du texte à une (miniature) Image:

(notez que vous devra fournir une police)

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); 
} 

Commentaires bienvenus.

0

Vous pouvez le faire en utilisant la fonction imagecopyresampled(). Heres un tutoriel facile et clair de l'ajout de filigrane aux vignettes. Vous pouvez également utiliser la fonction imagettftext() pour utiliser les polices comme filigrane

Tutoriel Lien: http://www.phpjabbers.com/phpexample.php?eid=20

Questions connexes