答案 0 :(得分:2)
使用默认的php函数(imagecopymerge)(GD库):
<?php
list($new_width, $new_height, $new_type, $new_attr) = getimagesize("newimage.png");
switch(image_type_to_mime_type($new_type)){
case IMAGETYPE_GIF:
$new = imagecreatefrompng('newimage.png');
break;
case IMAGETYPE_JPEG:
$new = imagecreatefromjpeg('newimage.png');
break;
case IMAGETYPE_PNG:
$new = imagecreatefromgif('newimage.png');
break;
}
$master = imagecreatefrompng('master.png');
imagealphablending($master, false);
imagesavealpha($demasterst, true);
imagecopymerge($master, $new, $box_x, $box_y, 0, 0, $box_w, $box_h, 100);
// imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )
//save image
imagepng($master, "file.png");
imagedestroy($master);
imagedestroy($new);
对于 jpeg 格式,请使用打击功能:
如果您不想存储,而只想将其发送给用户:
...
...
header('Content-Type: image/jpeg');
// Output the image
imagejpeg($master);
// Free up memory
imagedestroy($master);
imagedestroy($new);
答案 1 :(得分:0)
**此代码有效**
<?php
$image1 = 'images/template.png';
$image2 = 'images/1.png';
list($width,$height) = getimagesize($image2);
$image1 = imagecreatefromstring(file_get_contents($image1));
$image2 = imagecreatefromstring(file_get_contents($image2));
imagecopymerge($image1,$image2,40,100,0,0,$width,$height,100);
header('Content-Type:image/png');
imagepng($image1);
imagepng($image1,'merged.png');