问题描述
我对图像处理知之甚少,甚至使用的术语也少,所以请耐心等待。
I know very little of image processing and even less of the terminology used, so please bear with me.
基本上,我想将两个图像合并在一起,其中一个图像将作为遮罩。该图像看起来像这样:
蓝色和黄色背景在现实中都是透明的。
Basically, I want to merge two images together where one of them will act as a mask. That image looks something like this:
Where the blue and yellow background are both transparent in reality.
此图像用作常规照片的遮罩。 坚持圆圈的照片部分需要裁剪(变得不可见),同时内部仍然可见。
因此,蓝色区域内的所有内容都是隐形的,所有内容都在黄色区域是可见的。
This image is being used as a mask for regular photo's. Parts of the photo that 'stick out' of the circle need to be 'cropped' (be made invisible) while the inside remains visible.
So everything that comes in the blue area is invisible, everything in the yellow area is visible.
老实说,我不知道如何去做,所以任何帮助都将不胜感激!
I honestly have no clue how to go about it so any help would be greatly appreciated!
编辑
我使用的是Imagick的API版本,而不是命令行版本
I use the API version of Imagick, not the commandline version
编辑:
为了了解我想要实现的目标,这里有一个例子。
To get a feel of what I want to achieve, here is an example.
输入图像因此: br>
这是掩模图像,总是相同的
The input images are thus:
This is the mask image, always the same
这是图片的一个例子,动态
This is an example of a picture, dynamic
这就是最终结果应该是什么
This is what the end result should look like
推荐答案
所以,最后,这应该是做你需要的:
So, finally, this should do what you need:
代码:
<?php
$base = new Imagick('U0R4F.png');
$mask = new Imagick('mask.png');
$over = new Imagick('3ulkM.png');
// Setting same size for all images
$base->resizeImage(274, 275, Imagick::FILTER_LANCZOS, 1);
// Copy opacity mask
$base->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
// Add overlay
$base->compositeImage($over, Imagick::COMPOSITE_DEFAULT, 0, 0);
$base->writeImage('output.png');
header("Content-Type: image/png");
echo $base;
?>
我希望现在就是这样!
注意:在您的示例中,您看起来缩小了基本图像,我没有(我的目标只是显示屏蔽是如何完成的)。
I hope it's right now!Note: In your example it looks like you downscaled the base image, which I didn't (my goal is just to show how the masking is done).
这篇关于如何使用Imagick合并和屏蔽图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!