imagefilter() is a built-in function in PHP that allows developers to apply various filter effects to images. Using this function, you can apply a range of visual effects to an image, such as inverting colors, adjusting brightness and contrast, converting to grayscale, and more.
bool imagefilter(resource $image, int $filtertype, int $arg1, int $arg2, int $arg3, int $arg4)
The imagefilter() function takes six parameters:
Here are some commonly used image filter constants:
The function returns true on success and false on failure.
<?php // Load the image $img = imagecreatefromgif('C:\xampp\htdocs\Images\img39.gif'); <p>// Apply colorize filter<br> imagefilter($img, IMG_FILTER_COLORIZE, 140, 0, 140, 20);</p> <p>// Display the image<br> header('Content-type: image/gif');<br> imagepng($img);<br> ?><br>
<?php // Load the image $img = imagecreatefromgif('C:\xampp\htdocs\Images\img39.gif'); <p>// Apply negate filter<br> imagefilter($img, IMG_FILTER_NEGATE);</p> <p>// Display the image<br> header('Content-type: image/gif');<br> imagepng($img);<br> ?><br>
By using the imagefilter() function, PHP developers can easily apply various common filter effects to images. Whether it's a simple brightness adjustment or more complex edge detection and blur effects, this function can handle it all. Mastering these image processing techniques will enhance the visual experience and user interaction in your projects.