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

(singke) #1

$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();
}


//drop image2 into image, and stretch or squash it
imagecopyresized($image, $image2, 10, 10, 0, 0,
180, 180, imagesx($image2), imagesy($image2));


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


integer imagecreate(integer width, integer height)


The imagecreate function returns an image identifier of the specified width and height.
This identifier is used in many of the other image functions.


<?
/*
* Create a red square
/


//create red square
$image = imagecreate(200,200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $colorRed);


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


integer imagecreatefromjpeg(string filename)


Use imagecreatefromjpeg to load a JPEG image from a file.


<?
//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);

Free download pdf