imagefilter
(PHP 5)
imagefilter — 对图像使用过滤器
说明
bool imagefilter
( resource $src_im
, int $filtertype
[, int $arg1
[, int $arg2
[, int $arg3
]]] )
imagefilter() 把过滤器 filtertype 应用到图像上,在需要时使用 arg1 ,arg2 和 arg3 。
filtertype 可以是下列中的一个:
- IMG_FILTER_NEGATE :将图像中所有颜色反转。
- IMG_FILTER_GRAYSCALE :将图像转换为灰度的。
- IMG_FILTER_BRIGHTNESS :改变图像的亮度。用 arg1 设定亮度级别。
- IMG_FILTER_CONTRAST :改变图像的对比度。用 arg1 设定对比度级别。
- IMG_FILTER_COLORIZE :与 IMG_FILTER_GRAYSCALE 类似,不过可以指定颜色。用 arg1 ,arg2 和 arg3 分别指定 red ,blue 和 green 。每种颜色范围是 0 到 255。
- IMG_FILTER_EDGEDETECT :用边缘检测来突出图像的边缘。
- IMG_FILTER_EMBOSS :使图像浮雕化。
- IMG_FILTER_GAUSSIAN_BLUR :用高斯算法模糊图像。
- IMG_FILTER_SELECTIVE_BLUR :模糊图像。
- IMG_FILTER_MEAN_REMOVAL :用平均移除法来达到轮廓效果。
- IMG_FILTER_SMOOTH :使图像更柔滑。用 arg1 设定柔滑级别。
Note: 本函数仅在 PHP 与其捆绑的 GD 库一起编译时可用。
如果成功则返回 TRUE,失败则返回 FALSE。
Example#1 imagefilter() 灰度例子
<?php
$im = imagecreatefrompng('dave.png');
if ($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
echo 'Image converted to grayscale.';
imagepng($im, 'dave.png');
} else {
echo 'Conversion to grayscale failed.';
}
imagedestroy($im);
?>
Example#2 imagefilter() 亮度例子
<?php
$im = imagecreatefrompng('sean.png');
if ($im && imagefilter($im, IMG_FILTER_BRIGHTNESS, 20)) {
echo 'Image brightness changed.';
imagepng($im, 'sean.png');
} else {
echo 'Image brightness change failed.';
}
imagedestroy($im);
?>
Example#3 imagefilter() 上彩例子
<?php
$im = imagecreatefrompng('philip.png');
/* R, G, B, so 0, 255, 0 is green */
if ($im && imagefilter($im, IMG_FILTER_COLORIZE, 0, 255, 0)) {
echo 'Image successfully shaded green.';
imagepng($im, 'philip.png');
} else {
echo 'Green shading failed.';
}
imagedestroy($im);
?>