是否可以拍摄这张图片:
然后应用这个面具:
然后把它变成这样:
使用 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/