GD 函数
PHP 手册

imagefilter

(PHP 5)

imagefilter — 对图像使用过滤器

说明

bool imagefilter ( resource $src_im , int $filtertype [, int $arg1 [, int $arg2 [, int $arg3 ]]] )

imagefilter() 把过滤器 filtertype 应用到图像上,在需要时使用 arg1 ,arg2 和 arg3 。

filtertype 可以是下列中的一个:

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);
?>


GD 函数
PHP 手册