IMG_FILTER_GRAYSCALE: Converts the image into
grayscale by changing the red, green and blue components to their
weighted sum using the same coefficients as the REC.601 luma (Y')
calculation. The alpha components are retained. For palette images the
result may differ due to palette limitations.

IMG_FILTER_BRIGHTNESS: Changes the brightness
of the image. Use arg1 to set the level of
brightness. The range for the brightness is -255 to 255.

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, green,
blue 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.

Notes

See Also

User Contributed Notes 25 notes

The documentation misses the exact meaning and valid ranges of the arguments for ImageFilter(). According to the 5.2.0 sources the arguments are:IMG_FILTER_BRIGHTNESS-255 = min brightness, 0 = no change, +255 = max brightness

IMG_FILTER_COLORIZEAdds (subtracts) specified RGB values to each pixel. The valid range for each color is -255...+255, not 0...255. The correct order is red, green, blue.-255 = min, 0 = no change, +255 = maxThis has not much to do with IMG_FILTER_GRAYSCALE.

IMG_FILTER_SMOOTHApplies a 9-cell convolution matrix where center pixel has the weight arg1 and others weight of 1.0. The result is normalized by dividing the sum with arg1 + 8.0 (sum of the matrix).any float is accepted, large value (in practice: 2048 or more) = no change

ImageFilter seem to return false if the argument(s) are out of range for the chosen filter.

I needed an especially strong blur effect today and had a hard time achieving adequate results with the built-in IMG_FILTER_GAUSSIAN_BLUR filter. In order to achieve the strength of the blur I required I had to repeat the filter up to 100 times, which took way too long to be acceptable.

Function to change the transparency of a png image on the fly. Works only with PNG, and with a browser supporting alpha channel.The function stretches the opacity-range of the image, so that the most opaque pixel(s) will be set to the given opacity. (Other opacity values in pixels are modified accordingly.)Returns success or failure.

Note: applying IMG_FILTER_EMBOSS to text and using in a customization to the CAPTCHA image script in phpBB or a project of your own is a very good way to stop OCR-ing bots from getting through. Embossed serif fonts are fairly easy for the human eye to understand but to an OCR script it is extremely difficult because it seems to give it the illusion of 3D.

If you only allocate 2 or 3 colours in the image, it uses the background colour alot in the embossed text, which greatly contributes to this.

I made my own custom CAPTCHA script to stop phpBB post spam for a client site I was developing and I have gone from getting 2-3 new spam users created every day to zero.

Anything with the source code freely available out there right now is possible to be defeated by spammers once one of them stars sharing code with the other spammers, but if you run something at least someone custom, their bots will pass you over.

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

If you're looking for fast sepia effect that can be used for on-the-fly thumbnails generation you can't use sophisticated functions. The faster and much better way than described by webmaster at qudi dot de in the note from 31-Jan-2006 is applying colorize filter AFTER grayscale.

Searching for a way to easily change the color of the image, I tried IMG_FILTER_COLORIZE. I was unable to get the quality results I wanted. It turns out PHP's Colorize is the equivalent of Photoshop's "Linear Dodge" layer filter.

Hue adjustments have always worked well for me, so I figured I could try with PHP.This function is kind of slow on larger images, but on small images like what I'm using it for, the difference is trivial.

The script calculates the ratio or red, to green, to blue in the color provided, then scales the image appropriately... unfortunately, it does it pixel by pixel.

This routine was just what I was looking for, I wanted web admin users to be able to recolour their uploaded photos (to go with a news item) either a blue tint or sepia to match the appearance of other colours used on the website.

Using a form with a select box containing the RGB values, I can give them the option of either of the two tints or no colourization at all, plus resize their images to the viewing size and a thumbnail image on the fly without having to use any other image editing software.

//We will create a monochromatic palette based on//the input color//which will go from black to white//Input color luminosity: this is equivalent to the //position of the input color in the monochromatic//palette$lum_inp=round(255*($r+$g+$b)/765); //765=255*3

//We fill the palette entry with the input color at its //corresponding position

$pal[$lum_inp]['r']=$r;$pal[$lum_inp]['g']=$g;$pal[$lum_inp]['b']=$b;

//Now we complete the palette, first we'll do it to//the black,and then to the white.

//FROM input to black//===================//how many colors between black and input$steps_to_black=$lum_inp;