0

我正在尝试在图像上嵌入文本。我正在使用这个脚本http://www.phpjabbers.com/put-watermark-on-images-using-php-php20.html

这适用于一个文本。例如:我想要这样的文本

textone
texttwo
textthree

我希望它们低于一个。如何实现。我尝试使用

<p>$handlerData = "textone"; ?></p><p>$handlerData = "texttwo"; ?></p><p>$handlerData = "textthree"; ?></p>

但这只是嵌入第一个文本。

任何帮助,将不胜感激!

4

2 回答 2

0

你可以使用\n

$handlerData = 'textone'."\n".'texttwo'."\n".'textthree';

或者你可以改变这样的功能:

function watermarkImage ($source, $text, $destination, $x = 10, $y = 20) { 
   list($width, $height) = getimagesize($source);
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromjpeg($source);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); 
   $black = imagecolorallocate($image_p, 0, 0, 0);
   $font = 'arial.ttf';
   $font_size = 10; 
   imagettftext($image_p, $font_size, 0, $x, $y, $black, $font, $text);
   if ($DestinationFile<>'') {
      imagejpeg ($image_p, $destination, 100); 
   } else {
      header('Content-Type: image/jpeg');
      imagejpeg($image_p, null, 100);
   };
   imagedestroy($image); 
   imagedestroy($image_p); 
};

您现在可以使用 $x 和 $y 来定位文本。

于 2012-06-26T10:19:35.143 回答
0

您将为您的操作系统使用返回字符(\r、\n 或 \r\n)。PHP/GD 不会呈现 HTML。

[编辑]您发布的代码不会做任何与在图像上覆盖文本相关的事情,但您希望您的变量(在本例中为 $handlerData)包含回车符以换行:

$handlerData = "textone \r\n"
.              "texttwo \r\n"
.              "textthree \r\n";

这甚至可能有效:

$handlerData = "textone
texttwo
textthree ";

但是由于制表符之类的,您将有杂散的空白。如果这不起作用,您将需要发布您的实际代码

于 2012-06-26T10:16:10.217 回答