【问题标题】:PHP Merge 2 Images (Insert Face To An Image)PHP 合并 2 个图像(将人脸插入图像)
【发布时间】:2012-06-15 03:04:07
【问题描述】:

我需要你的帮助

我有两张图片,
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);
?>

问题是:
结果图像的分辨率与帧图像的分辨率不同,并且
如何改变人脸图像的位置,使人脸图像可以在帧图像的孔上

【问题讨论】:

  • 这个问题太宽泛了,显示缺乏文档阅读。不幸的是,我的票数不多了:)。
  • 嗨 user1450710,你找到这个任务的解决方案了吗?

标签: php image merge photo


【解决方案1】:

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

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_xdst_y

【讨论】:

    猜你喜欢
    • 2022-07-02
    • 2020-05-29
    • 2011-11-11
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多