Change the Brightness of a Picture
Current image taken from images file folder:
Select Brightness (0 = no change, 10 = brightest)
NOTE: The instructions below are NOT part of your assignment. As such, they do not need to be included in your final page.
Your assignment:
Create a form that works as this one does.
- The Sticky Radio Example;
- AND the Two Step Form from that Example;
- The slave script is listed below. You don't need to alter the code, just use it correctly "as-is".
Note this is a TWO STEP Form operation:
Form Step 1
Show the image (taken directly from the filesystem with sticky radio buttons ranging from 0 to 10. These radio buttons will allow the user to select the degree of brightness they want to apply to the image and then click Submit.
Form Step 2
Send the script Brightness values via a GET to the image slave brightness script (see below). This script ("bright.php"): 1) gets the image from the file system; 2) adjust the brightness of the image; 3) and then displays the image in part two of the form.
Also, provide the user with the option to do it again.
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/elle.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;
}
?>