PHP合并两张图片(将脸插入到一张图片中)

4

我需要你的帮助

我有两张图片,
1. http://i.imgur.com/pyWGk.jpg (人脸图像, 类型: jpeg)
2. http://i.imgur.com/LYk07.png (框架图像, 带有脸部空洞, 类型: png)

我想把人脸图像插入到框架图像中

我尝试了这个脚本

<?php
$image = imagecreatefromjpeg('face.jpg');
$frame = imagecreatefrompng('ironman.png');

$iw = imagesx($image);
$ih = imagesy($image);

$fw = imagesx($frame);
$fh = imagesy($frame);

imagealphablending($frame, true);
imagesavealpha($frame, true);
imagecopy($image, $frame, 0, 0, 0, 0, $fw, $fh);

header('Content-Type: image/jpeg');
imagejpeg($image);

imagedestroy($image);
imagedestroy($frame);
?>

问题如下:
结果图像的分辨率与框架图像的分辨率不同,以及
如何更改人脸图像的位置,使人脸图像在框架图像的孔上正确显示

这个问题范围太宽,显示出缺乏文档阅读的情况。不幸的是,我的关闭投票已经用完了 :). - kapa
你好,user1450710,你找到这个任务的解决方案了吗? - Bhavesh Lathigara
1个回答

0

您可以缩放图像以获得相同的分辨率。以下是缩放的示例代码:

function scale($scale){
    //you can get image width and height from image info
    $width = $image_width * $scale / 100;
    $height = $image_height * $scale / 100;

    $scaled_image = imagecreatetruecolor($width, $height);
    imagecopyresampled($scaled_image, $old_image, 0, 0, 0, 0, $width, $height, $image_width, $image_height);
}

要更改面部图像的位置,您可以在{{link1:imagecopy}}函数中设置所需的参数。您需要设置dst_xdst_y


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接