我需要你的帮助
我有两个图像,
1. https://i.stack.imgur.com/oSt6q.jpg(人脸图像,类型:JPEG)
2. https://i.stack.imgur.com/h9MNh.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);
?>
问题是:
结果图像的分辨率与帧图像的分辨率不同,并且
如何更改人脸图像的位置,以便人脸图像可以直接在帧图像中的孔上
您可以缩放图像以获得相同的分辨率。下面是用于缩放的示例代码:
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);
}
要更改面部图像的位置,您可以在imagecopy
函数中设置所需的参数。您需要设置dst_x
和dst_y
。