<?
/
Create a red image with a transparent
square cut out of it.
/
//create red square
$image = imagecreate(200,200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
$colorBlue = imagecolorallocate($image, 0, 0, 255);
imagefill($image, 0, 0, $colorRed);
//draw a smaller blue square
imagefilledrectangle($image, 30, 30, 70, 70, $colorBlue);
//make blue transparent
imagecolortransparent($image, $colorBlue);
//send image
header("Content-type: image/png");
imagepng($image);
?>
integer imagecopyresized(integer destination, integer source,
integer destination_x, integer destination_y, integer source_x,
integer source_y, integer destination_width, integer
destination_height, integer source_width, integer
source_height)
The imagecopyresized function copies a portion of the source image into the
destination image. If the destination width and height are different thanthe source width
and height, the clip will be stretched or shrunk. It is possible to copy and paste into the
same image, but if the destination and source overlap, there will be unpredictable results.
<?
/
Put PHP logo into field of red
and resize it to 180x180
/
//create red square
$image = imagecreate(200,200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $colorRed);
//attempt to open image, suppress error messages
if(!($image2 = @imagecreatefromjpeg("php_lang.jpg")))
{
//error, so create an error image and exit
$image = imagecreate(200,200);
$colorWhite = imagecolorallocate($image, 255, 255, 255);