Change the Brightness of a Picture
Current image taken from images file folder:
Select Brightness (0 = no change, 10 = brightest)
SLAVE CODE FOLLOWS
<?php // brightness script
// this takes an image from a database and changes it's bightness
$brightness = $_GET['br'];
// get the images from files
$image = imagecreatefromjpeg("images/ollie.JPG");
// get the palette from the image and create a 256 color palette
imagetruecolortopalette($image, true, 256);
// find the total number of colors in the palette
$totalColors = imagecolorstotal($image);
// now cycle through all the colors and change their brightness (see function)
for ($index = 0; $index < $totalColors; $index++)
{
// $RGB is an array
$RGB = imagecolorsforindex($image, $index);
$red = adjustBightness($RGB['red'], $brightness);
$green = adjustBightness($RGB['green'], $brightness);
$blue = adjustBightness($RGB['blue'], $brightness);
imagecolorset($image, $index, $red, $green, $blue);
}
// set the header for the image
header("Content-type: image/jpeg");
imagejpeg($image);
imagedestroy($image);
// ==== functions =======
function adjustBightness($color, $brightness)
{
// determine the color brightness
$color += (($brightness / 10) * 255);
// make sure the color value does not exceed 255
$color = ($color > 255) ? 255 : $color;
return $color;
}
?>