php imagick 滤镜,PHP Imagick filter()用法及代码示例

Imagick::filter()函数是PHP中的内置函数,用于将自定义卷积内核应用于图像。核,卷积矩阵或掩码是小矩阵。它用于模糊,锐化,压纹,边检测等。

用法:

bool Imagick::filter( $ImagickKernel, $channel = Imagick::CHANNEL_UNDEFINED )

参数:该函数接受上述和以下描述的两个参数:

$ImagickKernel:它是一个内核或一个由多个内核组成的链接系列,通常用于映像。

$channel:它是根据模式使用的常数。它是整数类型,并且通道的默认值为Imagick::CHANNEL_DEFAULT。

返回值:当成功将滤镜应用于图像时,它将返回true。

以下示例程序旨在说明PHP中的Imagick::filter()函数:

程序:

// Declare an imagick object

$imagick = new Imagick(

'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png');

// Declare convolution matrix

$matrix = [

[-1, 0, -1],

[0,  5,  0],

[-1, 0, -1],

];

$kernel = \ImagickKernel::fromMatrix($matrix);

$strength = 0.5;

// Scaling the image on kernel

$kernel->scale($strength, \Imagick::NORMALIZE_KERNEL_VALUE);

// Use addUnityKernel() function

$kernel->addUnityKernel(1 - $strength);

// Use filter() function

$imagick->filter($kernel);

header("Content-Type: image/jpg");

// Display the output image

echo $imagick->getImageBlob();

?>

输出:

525369b3a8c41c6e502e139f506f9715.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值