将多个 PNG 添加到图像 PHP


adding multiple pngs to image php

我正在图像上添加一行文本。是否可以将多行(line2.png和line3.png)叠加到同一图像上?

$stamp = imagecreatefrompng('img/line1.png');
$im = imagecreatefromjpeg('tom.jpg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 40;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo 
// width to calculate positioning of the stamp. 
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);

是的,您可以使用 imagecopy .

典型用法:

$copyimage = imagecreatefromjpeg("path/to/image/you/want/to/put/into/an/image.jpg");
//$copyimage just needs to be a GD object, so you can also use imagecreatefrompng etc.
imagecopy($image, $copyimage, $position_x, 
            $position_y, 0, 0, $image_width, $image_height);

http://php.net/imagecopy