[英]PHP GD image with 2 files
Here is what im trying to do. 这是我正在尝试做的事情。 Be advise im fairly new to
GD2
请告知我是
GD2
新手
I want to make an image out of 2 images this way; 我想以这种方式在2张图像中制作一张图像;
A background rectangle filled with images no 1 一个背景矩形,上面没有图像1
After that i want to draw a polygon
over it filled with another image. 之后,我想在上面绘制一个
polygon
,并填充另一个图像。
What i have right now is the rectangle and the image in background. 我现在所拥有的是矩形和背景图像。
I can draw the polygon but i cant figure out how to fill it with another image. 我可以绘制多边形,但无法弄清楚如何用其他图像填充多边形。 it is filled in blue right now and i would like to fill it with another image.
它现在以蓝色填充,我想用另一个图像填充它。
Heres my code 这是我的代码
$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);
as you can see imagepng()
render only $image
how do i get it to render $image and $image2 如您所见
imagepng()
仅渲染$image
我如何使其渲染$ image和$ image2
Thanks all 谢谢大家
You need to overlay the second image on top of the first. 您需要将第二个图像叠加在第一个图像之上。
$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);
I suggest you torn imagealphablending
off for Image2, draw an inverse of your polygon on Image2 with a color with alpha value: 0. Turn imagealphablending
on. 我建议您为
imagealphablending
撕开imagealphablending
,在imagealphablending
上绘制一个与alpha值为0的颜色相反的多边形。打开imagealphablending
。 And then you can copy Image2 over Image1 (the background). 然后,您可以将Image2复制到Image1(背景)上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.