我想做同样的事情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
正如您所看到的,它将信息放在图像的顶部...如何将其放置在图像下方?
答案 0 :(得分:1)
您必须创建比源高30px的新图像:
$img = imagecreatetruecolor($width_src, $height_dst + 30);
并将文字放在源图像的末尾,填满所有新空间:
$y1_rect = $height_dst;
$y2_rect = $height_dst + 30;