|
 |
imagefilter (PHP 5) imagefilter --
Applies a filter to an image
Descriptionbool imagefilter ( resource src_im, int filtertype [, int arg1 [, int arg2 [, int arg3]]] )
imagefilter() applies the filter
filtertype to the image, using
arg1, arg2 and
arg3 where necessary.
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. 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.
Замечание: Эта функция доступна только в том
случае, если PHP был скомпилирован со встроенной библиотекой GD.
Возвращает TRUE в случае успешного завершения или FALSE в случае возникновения ошибки.
Пример 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);
?>
|
|
Пример 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);
?>
|
|
Пример 3. imagefilter() colorize example
<?php
$im = imagecreatefrompng('philip.png');
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);
?>
|
|
imagefilter
santibari at fibertel dot com
27-Feb-2006 11:37
A colorize algorithm wich preserves color luminosity (i.e black
will output black, and white will output white).
This works in PHP4 and is great for customizing interfaces
dinamically.
<?php
function colorize($img_src,$img_dest, $r, $g, $b)
{
if(!$im = imagecreatefromgif($img_src))
return "Could not use image $img_src";
$lum_inp=round(255*($r+$g+$b)/765); $pal[$lum_inp]['r']=$r;
$pal[$lum_inp]['g']=$g;
$pal[$lum_inp]['b']=$b;
$steps_to_black=$lum_inp;
if($steps_to_black)
{
$step_size_red=$r/$steps_to_black;
$step_size_green=$g/$steps_to_black;
$step_size_blue=$b/$steps_to_black;
}
for($i=$steps_to_black;$i>=0;$i--)
{
$pal[$steps_to_black-$i]['r']=$r-round($step_size_red*$i);
$pal[$steps_to_black-$i]['g']=$g-round($step_size_green*$i);
$pal[$steps_to_black-$i]['b']=$b-round($step_size_blue*$i);
}
$steps_to_white=255-$lum_inp;
if($steps_to_white)
{
$step_size_red=(255-$r)/$steps_to_white;
$step_size_green=(255-$g)/$steps_to_white;
$step_size_blue=(255-$b)/$steps_to_white;
}
else
$step_size_red=$step_size_green=$step_size_blue=0;
for($i=($lum_inp+1);$i<=255;$i++)
{
$pal[$i]['r']=$r + round($step_size_red*($i-$lum_inp));
$pal[$i]['g']=$g + round($step_size_green*($i-$lum_inp));
$pal[$i]['b']=$b + round($step_size_blue*($i-$lum_inp));
}
for($c = 0; $c < $palette_size; $c++)
{
$col = imagecolorsforindex($im, $c);
$lum_src=round(255*($col['red']+$col['green']
+$col['blue'])/765);
$col_out=$pal[$lum_src];
imagecolorset($im, $c, $col_out['r'],
$col_out['g'],
$col_out['b']);
}
imagepng($im,$img_dest);
imagedestroy($im);
}?>
webmaster at qudi dot de
31-Jan-2006 06:53
for a quick, ok-looking, sepia-effect (also in php4) I just use this little fellow, since a real implementation of sepia was just way too slow.
function pseudosepia(&$im,$percent){
$sx=imagesx($im);
$sy=imagesy($im);
$filter=imagecreatetruecolor($sx,$sy);
$c=imagecolorallocate($filter,100,50,50);
imagefilledrectangle($filter,0,0,$sx,$sy,$c);
imagecopymerge($im,$filter,0,0,0,0,$sx,$sy,$percent);
}
vdepizzol at hotmail dot com
04-Sep-2004 01:36
Examples using 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);
?>
/////////////////////////////
<?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);
?>
/////////////////////////////
<?php
$im = imagecreatefrompng('philip.png');
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);
?>
kees at tweakers dot net
20-Jul-2004 06:26
From what i have been able to find from this function, it accepts the following arguments:
IMG_FILTER_NEGATE
IMG_FILTER_GRAYSCALE
IMG_FILTER_EDGEDETECT
IMG_FILTER_GAUSSIAN_BLUR
IMG_FILTER_SELECTIVE_BLUR
IMG_FILTER_EMBOSS
IMG_FILTER_MEAN_REMOVAL
The following arguments need one or more arguments.
IMG_FILTER_SMOOTH, -1924.124
IMG_FILTER_COLORIZE, -127.12, -127.98, 127
IMG_FILTER_CONTRAST, -90
IMG_FILTER_BRIGHTNESS, 98
I haven't tested them all, the names speak for themselves.
| |