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 に答える