Change the Brightness of Brody and Ada's Picture
Current image taken from images file folder:
Select Brightness (0 = no change, 5 = brightest)
SLAVE CODE FOLLOWS
<?php // brightness and text script
// takes an image and changes the brightness and then adds text to it
$brightness = isset($_GET['br']) ? $_GET['br'] : 0;
$text = "His calm. Her biggest fan.";
// get the image
$image = imagecreatefromjpeg("BrodyAda.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
for ($index = 0; $index < $totalColors; $index++)
{
// $RGB is an array
$RGB = imagecolorsforindex($image, $index);
$red = adjustBrightness($RGB['red'], $brightness);
$green = adjustBrightness($RGB['green'], $brightness);
$blue = adjustBrightness($RGB['blue'], $brightness);
imagecolorset($image, $index, $red, $green, $blue);
}
// copy the palette image back into a true color image before adding text
$trueColorImage = imagecreatetruecolor(imagesx($image), imagesy($image));
imagecopy($trueColorImage, $image, 0, 0, 0, 0, imagesx($image), imagesy($image));
imagedestroy($image);
$image = $trueColorImage;
// get sizes
$width = imagesx($image);
$height = imagesy($image);
// use arial font
$font = 'fonts/arial.ttf';
// sets the current foreground color to RGB (255, 0, 0) RED
$redText = imagecolorallocate($image, 255, 0, 0);
// combine the image with text using the following specs
// (image, font-size, angle-rotation, x-coord, y-coord, text-color, font-name, text)
// draw the text several times, slightly offset, to make it look bold
imagettftext($image, 22, 0, 20, $height - 30, $redText, $font, $text);
imagettftext($image, 22, 0, 21, $height - 30, $redText, $font, $text);
imagettftext($image, 22, 0, 20, $height - 29, $redText, $font, $text);
imagettftext($image, 22, 0, 21, $height - 29, $redText, $font, $text);
// set the header for the image
header("Content-type: image/png");
// display the image
imagepng($image);
// destroy the image
imagedestroy($image);
function adjustBrightness($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;
}
?>