PHP:如何使用alpha遮罩为图像创建阴影
我有一个带有alpha遮罩的PNG图像。我想为这个图像生成一个阴影,它将使用alpha遮罩 我想我需要:PHP:如何使用alpha遮罩为图像创建阴影,php,image-processing,gd,alpha-transparency,Php,Image Processing,Gd,Alpha Transparency,我有一个带有alpha遮罩的PNG图像。我想为这个图像生成一个阴影,它将使用alpha遮罩 我想我需要: 从第一张图像中获取alpha遮罩 用合适的颜色填充,然后模糊它 创建一个新的空白白色图像 首先用阴影和第一个图像组合它 但是我在任何地方都找不到一些提示,尤其是第一部分 编辑:我找到了一个开始的答案,我尝试了一下,让你知道 谢谢首先,您需要安装名为: 请先提供您的png文件。这很有效!!谢谢我仍在试图弄清楚它是如何工作的,但实际上,Image Magick shadow选项使用alpha层
谢谢首先,您需要安装名为:
请先提供您的png文件。这很有效!!谢谢我仍在试图弄清楚它是如何工作的,但实际上,Image Magick shadow选项使用alpha层。就这么简单@Matthieu,哈哈,你可以浏览手册来了解它是如何工作的
<?php
/* Read the image into the object */
$im = new Imagick( 'a.png' );
$im->setImageFormat("png");
/* Make the image a little smaller, maintain aspect ratio */
$im->thumbnailImage( 200, null );
/* Clone the current object */
$shadow = $im->clone();
/* Set image background color to black
(this is the color of the shadow) */
$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
/* Create the shadow */
$shadow->shadowImage( 80, 3, 5, 5 );
/* Imagick::shadowImage only creates the shadow.
That is why the original image is composited over it */
$shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 );
/* Display the image */
header( "Content-Type: image/png" );
echo $shadow;