当前位置: 首页> 函数类别大全> imagefilter

imagefilter

对图像应用滤镜
名称:imagefilter
分类:图像处理GD
所属语言:php
一句话介绍:对图像应用滤镜

imagefilter 函数

适用PHP版本

PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8

函数说明

imagefilter 函数用于对图像应用滤镜。该函数可以对 GD 库创建的图像进行滤镜效果处理,例如调节图像的对比度、亮度、饱和度,或者应用各种预设的视觉效果。

函数语法

bool imagefilter ( resource $image , int $filtertype [, int $arg1 = 0 [, int $arg2 = 0 [, int $arg3 = 0 ]]] )

参数

  • $image (必需): 要应用滤镜的图像资源,通常是由 imagecreatefrom... 函数生成的。
  • $filtertype (必需): 滤镜类型。可以使用常量来定义。
  • $arg1, $arg2, $arg3 (可选): 某些滤镜可能需要额外的参数。具体取决于滤镜类型。

返回值

如果成功,返回 true;如果失败,返回 false。

示例

以下是如何使用 imagefilter 函数将图像的亮度调整为 50 的示例:

示例代码

<?php
// 创建图像资源
$image = imagecreatefromjpeg('example.jpg');
<p>// 调整图像亮度<br>
imagefilter($image, IMG_FILTER_BRIGHTNESS, 50);</p>
<p>// 输出图像<br>
header('Content-Type: image/jpeg');<br>
imagejpeg($image);</p>
<p>// 释放内存<br>
imagedestroy($image);<br>
?><br>

示例代码的说明

  • 首先通过 imagecreatefromjpeg() 函数加载 JPEG 图像。
  • 然后,使用 imagefilter() 函数应用亮度滤镜(IMG_FILTER_BRIGHTNESS),并将亮度调整为 50。
  • 接着,设置响应头为图像类型并通过 imagejpeg() 输出处理后的图像。
  • 最后,使用 imagedestroy() 释放图像资源以节省内存。
同类函数
  • 返回此PHP版本支持的图像类型 imagetypes

    imagetypes

    返回此PHP版本支持的图像类型
  • 获取指定颜色的索引+ alpha或其最接近的替代选项 imagecolorresolvealpha

    imagecolorresolvealpha

    获取指定颜色的索引+alpha或其最接近
  • 设定用于填充的贴图 imagesettile

    imagesettile

    设定用于填充的贴图
  • 以给定角度旋转图像 imagerotate

    imagerotate

    以给定角度旋转图像
  • 区域填充到指定颜色的边界为止 imagefilltoborder

    imagefilltoborder

    区域填充到指定颜色的边界为止
  • 通过freetype2使用字体给出文本的边界框 imageftbbox

    imageftbbox

    通过freetype2使用字体给出文本的
  • 找出图像调色板中的颜色数 imagecolorstotal

    imagecolorstotal

    找出图像调色板中的颜色数
  • 将二进制IPTC数据嵌入JPEG图像 iptcembed

    iptcembed

    将二进制IPTC数据嵌入JPEG图像
热门文章