01-11-2010, 02:57 PM
In this tutorial I'll show you how to manipulate images using the function imagefilter().
bool imagefilter ( resource $image , int $filtertype [, int $arg1 [, int $arg2 [, int $arg3 [, int $arg4 ]]]] )
I'll use my current signature to show you what we can do.
The function uses 4 argument variables, all of the type INT. It depends on which $filtertype you choose, how many arguments you need to define..
First we need an image resource, since the image I'm using is a PNG one, I use imagecreatefrompng() to create the needed image resource.
And this is the original image;
To start off simple, I'll show you how to use imagefilter() to reverse image colors.
For this case we use the $filtertype IMG_FILTER_NEGATE, this type doesn't require any other arguments set..
The function would be called like this;
Our image would now look like this;
So far, it's simple isn't it...
Now let me show you how to use imagefilter() to convert the image to Grayscale...
This one is also pretty simple, since this filter type also doesn't require any other arguments defined.
The effect of the function would turn the image into something like this;
Our next filter type is IMG_FILTER_BRIGHTNESS, which requires $arg1 defined.
$arg1 is used to set the level of brightness, the integer value can be set from -255 to 255. (dark/light)
I will set the brightness level to 100.
The image now looks like this;
We also have a Contrast filter, IMG_FILTER_CONTRAST, uses $arg1 to set the lavel for the contrast.
I will set the level to -25.
After executing this filter, the image would look like this;
Next on our filter type list is, IMG_FILTER_COLORIZE, this filter uses all 4 argument variables.
$arg1 is used to set level for the RED color, $arg2 is used for the GREEN color, $arg3 is used to set the lavel of the BLUE color and the last
argument is used to set the alpha level of the defined RGB value. ($arg4 can be set from 0 to 127, 0 is completely opaque and 127 completely transparent)
I will add a violet color and set it's alpha level to 60.
The image would be now;
Our next filter type, IMG_FILTER_EDGEDETECT, doesn't use any other arguments.
The converted image looks like this;
The next filter is, IMG_FILTER_EMBOSS, which also doesn't need any other arguments.
The image with this filter applied would look like this;
We can also blur the image, and there are 2 filter types for this case, I will only talk about gaussian blur.
This filter type doesn't use any arguments....
The blured image looks like this;
Going to the naxt filter, IMG_FILTER_MEAN_REMOVAL, this will use mean removal to achieve a "sketchy" effect.
The filter type doesn't use any arguments either.
Our "sketchy" image would look like this;
Next filter is, IMG_FILTER_SMOOTH, this filter type uses $arg1 to set the smoothness level. 0 = Blured => 100 = Smooth
Image now looks like this; (not a real difference ;) )
And we are now at the last filter type, IMG_FILTER_PIXELATE, this filter uses 2 arguments, $arg1 is required while $arg2 by default is defined as FALSE (0).
$agr1 is used to set the block size in pixels and $arg2 is used to enable/disable advanced pixelation effect.
I'll set the block size to 5 pixel ($arg1) and use the advanced pixelation effects.
The image now looks like this;
END
Thank you for reading and have fun Photoshop-ing with PHP.
ps:
I want to thank Tasemu again for the Signature... Thank you! ;)
And please notify me if images are not loading, thank you!
bool imagefilter ( resource $image , int $filtertype [, int $arg1 [, int $arg2 [, int $arg3 [, int $arg4 ]]]] )
I'll use my current signature to show you what we can do.
The function uses 4 argument variables, all of the type INT. It depends on which $filtertype you choose, how many arguments you need to define..
First we need an image resource, since the image I'm using is a PNG one, I use imagecreatefrompng() to create the needed image resource.
PHP Code:
$img = imagecreatefrompng("sig.png");
/*
- We will place our imagefilter() function between those lines,
- before we output it with the imagepng() function
*/
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
And this is the original image;
To start off simple, I'll show you how to use imagefilter() to reverse image colors.
For this case we use the $filtertype IMG_FILTER_NEGATE, this type doesn't require any other arguments set..
The function would be called like this;
PHP Code:
imagefilter($img, IMG_FILTER_NEGATE);
Our image would now look like this;
So far, it's simple isn't it...
Now let me show you how to use imagefilter() to convert the image to Grayscale...
This one is also pretty simple, since this filter type also doesn't require any other arguments defined.
PHP Code:
imagefilter($img, IMG_FILTER_GRAYSCALE);
The effect of the function would turn the image into something like this;
Our next filter type is IMG_FILTER_BRIGHTNESS, which requires $arg1 defined.
$arg1 is used to set the level of brightness, the integer value can be set from -255 to 255. (dark/light)
I will set the brightness level to 100.
PHP Code:
imagefilter($img, IMG_FILTER_BRIGHTNESS, 100);
The image now looks like this;
We also have a Contrast filter, IMG_FILTER_CONTRAST, uses $arg1 to set the lavel for the contrast.
I will set the level to -25.
PHP Code:
imagefilter($img, IMG_FILTER_CONTRAST, -25);
After executing this filter, the image would look like this;
Next on our filter type list is, IMG_FILTER_COLORIZE, this filter uses all 4 argument variables.
$arg1 is used to set level for the RED color, $arg2 is used for the GREEN color, $arg3 is used to set the lavel of the BLUE color and the last
argument is used to set the alpha level of the defined RGB value. ($arg4 can be set from 0 to 127, 0 is completely opaque and 127 completely transparent)
I will add a violet color and set it's alpha level to 60.
PHP Code:
imagefilter($img, IMG_FILTER_COLORIZE, 100, 75, 180, 60);
The image would be now;
Our next filter type, IMG_FILTER_EDGEDETECT, doesn't use any other arguments.
PHP Code:
imagefilter($img, IMG_FILTER_EDGEDETECT);
The converted image looks like this;
The next filter is, IMG_FILTER_EMBOSS, which also doesn't need any other arguments.
PHP Code:
imagefilter($img, IMG_FILTER_EMBOSS);
The image with this filter applied would look like this;
We can also blur the image, and there are 2 filter types for this case, I will only talk about gaussian blur.
This filter type doesn't use any arguments....
PHP Code:
imagefilter($img, IMG_FILTER_GAUSSIAN_BLUR);
The blured image looks like this;
Going to the naxt filter, IMG_FILTER_MEAN_REMOVAL, this will use mean removal to achieve a "sketchy" effect.
The filter type doesn't use any arguments either.
PHP Code:
imagefilter($img, IMG_FILTER_MEAN_REMOVAL);
Our "sketchy" image would look like this;
Next filter is, IMG_FILTER_SMOOTH, this filter type uses $arg1 to set the smoothness level. 0 = Blured => 100 = Smooth
PHP Code:
imagefilter($img, IMG_FILTER_SMOOTH, 50);
Image now looks like this; (not a real difference ;) )
And we are now at the last filter type, IMG_FILTER_PIXELATE, this filter uses 2 arguments, $arg1 is required while $arg2 by default is defined as FALSE (0).
$agr1 is used to set the block size in pixels and $arg2 is used to enable/disable advanced pixelation effect.
I'll set the block size to 5 pixel ($arg1) and use the advanced pixelation effects.
PHP Code:
imagefilter($img, IMG_FILTER_PIXELATE, 5, TRUE);
The image now looks like this;
END
Thank you for reading and have fun Photoshop-ing with PHP.
ps:
I want to thank Tasemu again for the Signature... Thank you! ;)
And please notify me if images are not loading, thank you!