这是我想要做的.建议我相当新GD2
我想以这种方式用2张图像制作图像;
背景矩形填充图像没有1
在那之后,我想画一个polygon充满了另一个图像.
我现在拥有的是矩形和背景图像.
我可以绘制多边形,但我无法弄清楚如何用另一个图像填充它.它现在填充蓝色,我想用另一个图像填充它.
继承我的代码
$values = array(
40, 50, // Point 1 (x, y)
20, 240, // Point 2 (x, y)
60, 60, // Point 3 (x, y)
240, 20, // Point 4 (x, y)
50, 40, // Point 5 (x, y)
10, 10 // Point 6 (x, y)
);
$image2 = imagecreatefromjpeg('test2.jpg');
$image = imagecreatefromjpeg('test.jpg');
$bg = imagecreatefromjpeg('test.jpg');
$fill = imagecolorallocate($image, 0, 0, 255);
// fill the background
imagefilledrectangle($image, 0, 0, 249, 249, $bg);
// draw a polygon
imagefilledpolygon($image, $values, 6, $fill);
// flush image
header('Content-type: image/jpg');
imagepng($image);
imagedestroy($image);
Run Code Online (Sandbox Code Playgroud)
你可以看到imagepng()渲染只是$image如何让它渲染$ image和$ image2
谢谢大家
您需要将第二个图像叠加在第一个图像的顶部.
$file1 = 'test.jpg';
$file2 = 'test2.jpg';
// First image
$image = imagecreatefromjpeg($file1);
// Second image (the overlay)
$overlay = imagecreatefromjpeg($file2);
// We need to know the width and height of the overlay
list($width, $height, $type, $attr) = getimagesize($file2);
// Apply the overlay
imagecopy($image, $overlay, 0, 0, 0, 0, $width, $height);
imagedestroy($overlay);
// Output the results
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
Run Code Online (Sandbox Code Playgroud)