What PHP function can be used to color images?

To color images in PHP, you can use the imagefilter() function. This function applies a filter to an image resource, allowing you to change its appearance. One of the filters available is IMG_FILTER_COLORIZE, which can be used to add color to an image by adjusting the RGB values.

// Load the image
$image = imagecreatefromjpeg('image.jpg');

// Apply colorizing filter (e.g. red color)
imagefilter($image, IMG_FILTER_COLORIZE, 255, 0, 0);

// Output the image
header('Content-Type: image/jpeg');
imagejpeg($image);

// Free up memory
imagedestroy($image);