Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

* Attempt to draw a magenta square
/


//attempt to open image, suppress error messages
if(!($image = @imagecreatefromjpeg("php_lang.jpg")))
{
//error, so create an error image and exit
$image = imagecreate(200,200);
$colorWhite = imagecolorallocate($image, 255, 255, 255);
$colorBlack = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $colorWhite);
imagestring($image, 4, 10, 10, "Couldn't load image!",
$colorBlack);
header("Content-type: image/jpeg";
imagejpeg($image);
exit();
}


$colorMagenta = imagecolorresolve($image, 255, 0, 255);


// draw a square
imagefilledrectangle($image, 10, 10, 50, 50, $colorMagenta);


//send ima
header("Content-type: image/jpeg");
imagejpeg($image);
?>


boolean imagecolorset(integer image, integer index, integer
red, integer green, integer blue)


The imagecolorset function sets the color at the given index to the specified color. For
an example of use, see the example for the imagecolorat function.


array imagecolorsforindex(integer image, integer index)


The imagecolorsforindex function returns an associative array with the red, green, and
blue elements of the color for the specified color index.


<?
/*
* Show RGB values for a color
/


//attempt to open image, suppress error messages
if(!($image = @imagecreatefromjpeg("php_lang.jpg")))
{
//error, so create an error image and exit
$image = imagecreate(200,200);
$colorWhite = imagecolorallocate($image, 255, 255, 255);
$colorBlack = imagecolorallocate($image, 0, 0, 0);

Free download pdf