可能重复:
面部识别/检测 PHP 或照片和视频库软件
我正在尝试编码以将肖像合并到可用的框架图片中。通过使用 WideImage PHP Lib,我可以对图像进行操作,这是我的代码:
//Load image from disk
$img = WideImage::load($fileName); //our character
$watermark = WideImage::load($framePath.'photo_frame.png'); //load frame picture
//crop img to fit into frame
$hWatermark = $watermark->getHeight();
$wWatermark = $watermark->getWidth();
$img = $img->resize($wWatermark, $hWatermark, "outside");
$hImg = $img->getHeight();
$wImg = $img->getWidth();
if($hImg > $hWatermark) {
$img = $img->crop(0, 0, $width = "100%", $height = $hWatermark);
}
if($wImg > $wWatermark) {
$img = $img->crop(0, 0, $width = $wWatermark, $height = "100%");
}
// place the frame override image
$new = $img->merge($watermark, $left = 0, $top = 0, $pct = 100);
//Result is a new image with our character in a frame
$new->output('jpg', 90);
使用上面的块代码,我可以制作一张新图片,但是如果脸部不在左上角附近,则新图片不会聚焦到脸部。例子:
我想我写不出代码来自动检测人脸,但是我们有一个简单的方法是让用户选择一个区域来拼贴。如何以这种方式在 HTML 和 js 上实现?感谢您的帮助!