答案 0 :(得分:12)
使用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;
答案 1 :(得分:1)
我认为您正在寻找imagealphablending。我用它来做水印,我相信它会起到你想要的效果。
答案 2 :(得分:0)
很棒的工作(ImageMagick)NOT GD ..我看到这个问题的标签是GD !!
以下是此链接的GD版本: PHP GD Use one image to mask another image, including transparency