1

我想对 9gag 的图像做同样的事情......

但到目前为止,我只能在图像顶部添加水印,添加额外的空间......

这是原始图片: http: //www.matamoros.gob.mx/test/595.jpg

这是我的代码:

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

$img_name = "595.jpg";

$img_src = imagecreatefromjpeg($img_name);

$width_src = imagesx($img_src);

$height_src = imagesy($img_src);

$width_dst = $width_src;

$height_dst = $height_src;

$quality = 80;

$img = imagecreatetruecolor($width_src, $height_dst);

imagecopyresampled($img, $img_src, 0, 0, 0, 0, $width_dst, $height_dst, $width_src, $height_src);

$x1_rect = 0;

$y1_rect = $height_dst - 30;

$x2_rect = $width_dst;

$y2_rect = $height_dst;

$color = imagecolorallocate($img, 245, 245, 245);

$letter_color = imagecolorallocate($img, 140, 140, 140);

$text = "http://en1.me/f/xxxxxxxx";

imagefilledrectangle($img, $x1_rect, $y1_rect, $x2_rect, $y2_rect, $color);

imagettftext($img, 20, 0, $x1_rect+5, $y1_rect+22, $letter_color, "Harabara.ttf", $text);

imagejpeg($img, '', $quality);

imagedestroy($img_src);

imagedestroy($img);

这就是结果: http: //www.matamoros.gob.mx/test/test2.php

如您所见,它将信息放在图像的顶部……我怎样才能使它位于图像下方?

4

1 回答 1

1

您必须创建比源高 30px 的新图像:

$img = imagecreatetruecolor($width_src, $height_dst + 30);

并将您的文本从源图像的末尾开始,填充所有新空间:

$y1_rect = $height_dst;
$y2_rect = $height_dst + 30;
于 2012-10-18T17:41:37.053 回答