<?
// GIF transparency works with imagecreate (with or without using imagefill)
//  PNG transparency works with imagecreate (with or without using imagefill) and imagecreatetruecolor
// Default background for imagecreatetruecolor is black. For imagecreate, 
// default is the first color you allocate. If no colors are allocated before
// you create the image, there will be none.

$width = 400; $height = 400;

// (1) Create the image. You can also create the image
// from an existing one (see the other examples).
$im = imagecreate($width,$height);
#$im = imagecreatetruecolor($width,$height);

// (2) Allocate colors
$green=imagecolorallocate($im,0,128,0);
$red=imagecolorallocate($im,255,0,0);
$black=imagecolorallocate($im,0,0,0);
$white=imagecolorallocate($im,255,255,255);
$blue=imagecolorallocate($im,0,0,255);
$yellow = ImageColorAllocate ($im, 255, 255, 0);

// Function imagefill is useful for the background 
// of the image when you use imagecreate.
// If you use imagecreatetrue color, the automatic
// background will be black.
imagefill($im,0,0,$yellow); 

// You can set a transparent color (blue in this case)
imagecolortransparent($im,$green);

// (3) Draw what you want to draw
// You can draw a filled rectangle
imagefilledrectangle($im,50,50,$width-50,$height-50,$green);
imagefilledrectangle($im,100,100,$width-100,$height-100,$red);
imagestring($im,5,51,51,"1",$red);
imagestring($im,5,$width-58,51,"2",$red);
imagestring($im,5,$width-58,$height-64,"3",$red);
imagestring($im,5,50,$height-64,"4",$red);
// You can change the thikness of lines
imagesetthickness($im,5);
imagesetpixel($im,30,40,$red);
imagesetpixel($im,30,41,$red);
imagesetpixel($im,31,40,$red);
imagesetpixel($im,29,40,$red);
imagesetpixel($im,30,39,$red);

// You can draw a part of an ellipse
imagefilledarc($im,$width/2,$width/2,50,50,90,180,$black,IMG_ARC_NOFILL);
imagefilledarc($im,$width/2,$width/2,70,70,90,180,$black,IMG_ARC_NOFILL+IMG_ARC_EDGED);
imagearc($im,$width/2,$width/2,100,100,90,180,$black);

// You can rotate the image
#$im = ImageRotate($im,45,$black);

//You can copy images (in this case, $im3 will be copied to $im2)
#$im2 = imagecreatetruecolor(400,400);
#$im3 = imagecreatefrompng("/home/abu-jeib/proposals/abc.png");

// You can copy the image or part of it
#imagecopy($im2,$im3,$width,0,0,0,$width,$height);

// (4) Send the image to the browser. You can 
// also save it to a file (see below)
header("Content-type: image/png");
imagepng($im);

// Here is how to save the image to a file
ImagePNG($im,"/home/abu-jeib/proposals/graphics1.png");

#imagepng($im2);

/*header("Content-type: image/jpeg");
imagejpeg($im);*/

/*
header("Content-type: image/gif");
imageGIF($im);
*/

// (5) Free the memory allocated for the image
ImageDestroy($im);

?>
