imagefilter
(PHP 5)
imagefilter — Applies a filter to an image
설명
bool imagefilter
( resource $image
, int $filtertype
[, int $arg1
[, int $arg2
[, int $arg3
[, int $arg4
]]]] )
imagefilter() applies the given filter filtertype on the image .
매개변수
- font
-
내장 글꼴 1, 2, 3, 4, 5(큰 숫자가 큰 글꼴)나 imageloadfont()로 등록한 글꼴 식별자를 사용할 수 있습니다.
- filtertype
-
filtertype can be one of the following:
- IMG_FILTER_NEGATE: Reverses all colors of the image.
- IMG_FILTER_GRAYSCALE: Converts the image into grayscale.
- IMG_FILTER_BRIGHTNESS: Changes the brightness of the image. Use arg1 to set the level of brightness.
- IMG_FILTER_CONTRAST: Changes the contrast of the image. Use arg1 to set the level of contrast.
- IMG_FILTER_COLORIZE: Like IMG_FILTER_GRAYSCALE, except you can specify the color. Use arg1 , arg2 and arg3 in the form of red , blue , green and arg4 for the alpha channel. The range for each color is 0 to 255.
- IMG_FILTER_EDGEDETECT: Uses edge detection to highlight the edges in the image.
- IMG_FILTER_EMBOSS: Embosses the image.
- IMG_FILTER_GAUSSIAN_BLUR: Blurs the image using the Gaussian method.
- IMG_FILTER_SELECTIVE_BLUR: Blurs the image.
- IMG_FILTER_MEAN_REMOVAL: Uses mean removal to achieve a "sketchy" effect.
- IMG_FILTER_SMOOTH: Makes the image smoother. Use arg1 to set the level of smoothness.
- arg1
-
- arg2
-
- arg3
-
반환값
성공할 경우 TRUE를, 실패할 경우 FALSE를 반환합니다.
변경 기록
버전 | 설명 |
---|---|
5.2.5 | Alpha support for IMG_FILTER_COLORIZE was added. |
예제
Example#1 imagefilter() grayscale example
<?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() brightness example
<?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() colorize example
<?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);
?>
주의
Note: 이 함수는 PHP에 포함된 GD 라이브러리를 사용하여 컴파일하였을 경우에만 사용할 수 있습니다.