Avatar of tech1984
tech1984

asked on 

Using php GD to watermark an image, need to have line breaks.

I have an attached script that creates a watermark of a copyright symbol over the photo, However I would like to allow for line breaks in the $WaterMarkText variable. This way I could have a copyright symbol and the company name under that.

Thanks for your time


$photo_name = "AC001.jpg";
$gallery_name = "Fall Colors";
 
function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) {
   list($width, $height) = getimagesize($SourceFile);
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromjpeg($SourceFile);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
   $black = imagecolorallocatealpha($image_p, 255, 255, 255, 99);
   $font = '../admin/arial.ttf';
   $font_size = 400;
   $overlay_height = "391";
   $overlay_width = "395";
   
   $o_width = $overlay_width/2; 
   $i_width = $width/2;	  
   $x_pos = $i_width - $o_width; 
   
   $o_height = $overlay_height/2;    
   $i_height = $height/2;	  
   $y_pos = $i_height + $o_height; 
   
   imagettftext($image_p, $font_size, 0, $x_pos, $y_pos, $black, $font, $WaterMarkText);
   if ($DestinationFile<>'') {
      imagejpeg ($image_p, $DestinationFile, 100);
   } else {
      header('Content-Type: image/jpeg');
      imagejpeg($image_p, null, 100);
   };
   imagedestroy($image);
   imagedestroy($image_p);
};
 
$SourceFile = "../galleries/$gallery_name/$photo_name";
$DestinationFile = "";
$WaterMarkText = '©';
watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);

Open in new window

PHP

Avatar of undefined
Last Comment
Cem Türk

8/22/2022 - Mon