gpt4 book ai didi

php - 使用透明 PNG 作为剪贴蒙版

转载 作者:可可西里 更新时间:2023-10-31 23:09:44 25 4
gpt4 key购买 nike

是否可以拍摄这张图片:

image1

然后应用这个面具:

mask

然后把它变成这样:

image2

使用 GD 还是 Imagick?我知道可以使用形状来遮盖图像,但我不确定如何使用预先创建的 alphatransparent 图像继续这样做。 :s

最佳答案

使用 Imagick 和 ImageMagick 版本 > 6(我不知道它是否适用于旧版本):

// Set image path
$path = '/path/to/your/images/';

// Create new objects from png's
$dude = new Imagick($path . 'dude.png');
$mask = new Imagick($path . 'dudemask.png');

// IMPORTANT! Must activate the opacity channel
// See: http://www.php.net/manual/en/function.imagick-setimagematte.php
$dude->setImageMatte(1);

// Create composite of two images using DSTIN
// See: http://www.imagemagick.org/Usage/compose/#dstin
$dude->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0);

// Write image to a file.
$dude->writeImage($path . 'newimage.png');

// And/or output image directly to browser
header("Content-Type: image/png");
echo $dude;

关于php - 使用透明 PNG 作为剪贴蒙版,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1741488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com