Back To Top
Code OutPut
Basic Image
//Generate the image properties
$height = 100;
$width = 100;
$img = imagecreate($width, $height);
$bk_color = imagecolorallocate($img, 0, 45, 0);

//Call the image
header("Content-Type: image/png");
imagepng($img);

//Destroy the image
imagedestroy($img);
imagefilledpolygon
$values = array(
10,10,// Point 1 (x, y)
80,10,// Point 2 (x, y)
80,20,// Point 3 (x, y)
50,20,// Point 4 (x, y)
50,90,// Point 5 (x, y)
40,90,// Point 6 (x, y)
40,20,// Point 7 (x, y)
10,20,// Point 8 (x, y)
);

//Generate the image properties
$img = imagecreate(100, 100);
$background_color = imagecolorallocate($img, 0, 0,255);
$text_color = imagecolorallocate($img, 0, 255, 0);

//Call the image ($img, $values, $num_of_points, $text_color);
imagefilledpolygon($img, $values, 8, $text_color);
header("Content-Type: image/png");
imagepng($img);

//Destroy the image
imagedestroy($img
polygon image with 8 points to create a T
imagearc()
//base image
$img = imagecreate(200, 200);
$bkg_color=$arc_color=imagecolorallocate($img, 0,0,0);

//creating the arcs inside the image
$center_x=100;
$center_y=100;
$arc_width=150;
$arc_height=150;
$arc_start=0; //The arc start angle, in degrees.
$arc_end=180; //The arc end angle, in degrees. 0 is located at the three-o'clock position, and the arc is drawn clockwise.
$arc_color=imagecolorallocate($img, 0,152,12);

//draw your arc(s)
imagearc($img, $center_x, $center_y, $arc_width, $arc_height, $arc_start, $arc_end, $arc_color);
imagearc($img, 75, 75, 45, 25, 0, 360, $arc_color); //
imagearc($img, 125, 75, 45, 25, 0, 360, $arc_color);
imagearc($img, 100, 125, 100, 55, 0, 180, $arc_color);

//Output the image
header("Content-type: image/png");
imagepng($img);

// free memory
imagedestroy($img);
image arc
imagefilledrectangle()
//create the basic image
$img = imagecreatetruecolor(200,200);
$bkg_color = imagecolorallocate($img, 0,0,0);

//colors
$orange = imagecolorallocate($img, 255, 100, 0);

//recangle points
$x_1 = 50; //x-coordinate for point 1.
$y_1 = 50; //y-coordinate for point 1.
$x_2 = 150; //x-coordinate for point 2
$y_2 = 150; //y-coordinate for point 2

// Draw a square
imagefilledrectangle($img, $x_1, $y_1, $x_2, $y_2, $orange );

//Output Image
header('Content-Type: image/png');
imagepng($img);

//Destroy the image
imagedestroy($img);
imagecolortransparent()
//create the basic image
$img = imagecreatetruecolor(200,200);
$bkg_color = imagecolorallocate($img, 0,0,0);

//colors
$orange = imagecolorallocate($img, 255, 100, 0);
$green = imagecolorallocate($img, 0,255,0);

// Draw a square
imagefilledrectangle($img, 50, 50, 150, 150, $orange );
imagefilledrectangle($img, 70, 70, 130, 130, $green );

//Make the Orange recangle disapear
imagecolortransparent ($img, $orange);

//Output Image
header('Content-Type: image/png');
imagepng($img);

//Destroy the image
imagedestroy($img);
imagecreatefromjpeg()
$img=imagecreatefromjpeg('bg3.jpg');

//Output Image
header("Content-Type: image/jpeg");
imagejpeg($img);

//Destroy the image
imagedestroy($img);
imagecreatefrompng()
$img=imagecreatefrompng('bg6.png');

//Output Image
header("Content-Type: image/png");
imagepng($img);

//Destroy the image
imagedestroy($img);
imagettftext()
//basic image
$img = imagecreatetruecolor(200, 200);
$bk_color = imagecolorallocate($img, 0, 0, 0);

//colors to use
$white = imagecolorallocate($img, 255, 255, 255);

//fonts to use
$caberet = 'Caberet.ttf';

//imagettftext ( $image , $size , $angle , $x , $y , $color , $fontfile , $text )
imagettftext($img, 25 , 45 , 25, 75, $white, $caberet, "hEllo \n There \n My Friend");

//Output Image
header("Content-Type: image/png");
imagepng($img);

//Destroy the image
imagedestroy($img);
imagestring()
Here I am going to create an image with text and a transpareant back ground. I am going to give it a border for the purpose of showing you thatt the is a back ground. This works best with imagecreate() instead of imagecreatetruecolor(). This is due to the fact that with imagecreate() you choose the background color where as it is always black with true color.

//base image
$img = imagecreate(240,16);
$bk_color = imagecolorallocate($img, 0, 0, 0);

//Colors
$red = imagecolorallocate($img, 255,0,0);

// Add text
imagestring($img, 5, 10, 0, 'AllProCompanys@gmail.com', $red);

//make background disapear
imagecolortransparent($img, $bk_color);

//Output Image
header("Content-Type: image/png");
imagepng($img);

//Destroy the image
imagedestroy($img);

Here I removed the background color



Here I removed the text color



Here none of the colors have been removed.