Everyone interested in PHP image drawing functions to create simple objects like Rectangle, Line or Circles using GD library support.
The following simple tutorial helps to manipulate images/pictures in website:
Here I will explain how to draw an picture/image for the above objects. First of all you should take some preliminary steps to ensure better output while running our following codes to your Windows 98/2000/NT/XP/Vista or Linux(Ubuntu, Solaris, FreeBSD, or other Unix based) systems.

Website Images
Requirements:
- PHP Version: 4.3 +
- MySQL: ——
- GD Library: already bundled (if not click here)
- Browser: IE 6.0+, Mozilla Firefox 2.0+, Opera 8+, Safari or Chrome
- Server: Apache
Why the GD Library?
The answer is, GD is an open source code library for the dynamic creation of images by programmers. The GD creates PNG, JPEG and GIF images, among other formats. It is commonly used to generate charts, graphics, thumbnails, image conversion, resizing and most anything else, on the fly. While not restricted to use on the web, the most common applications of GD involve web site development.
To draw simple images like rectangle, line or circles we need this graphic library support.
To download latest version of free GD library from its official website at http://www.libgd.org/releases/gd-2.0.35.tar.gz available now.
Note:- All the PHP current releases has bundled with GD library support so no need to download again.
To check whether PHP in gd library installed or not you should type the following code in your program:
else
echo “GD extension not found – break all operations”;
?>
The step by step instuctions explained with example progrma below:
/********* CREATING AN RECTANGLE OVER WEB **********/
// Define an Empty Image(WIDTH x HEIGHT) resource
$image = imagecreate(300, 250);
// set background color of working window – here yellow
$back_color=imagecolorallocate($image,255,255,0);
/********* DRAWING AN RECTANGLE OVER WEB **********/
// Standard color = RGB(Red Green Blue) = 0-255(255 255 255)
$rectangle_color = imagecolorallocate($image, 200, 10, 190);
$top_leftX=10; $top_leftY=60; $bottom_rightX=60; $bottom_rightY=10;
imagerectangle($image, $top_leftX, $top_leftY, $bottom_rightX, $bottom_rightY, $rectangle_color );
/******* DRAWING A NEW CIRCLE/ELLIPSE IN IMAGE *********/
$circle_color = imagecolorallocate($image, 25, 55, 255);
// Draw the Circle/Ellipse on workspace(350×250)
$x=100; $y=100; $width=100; $height=100;
imageellipse($image, $x, $y, $width, $height, $circle_color);
/********* DRAWING A NEW LINE IN IMAGE ***********/
$line_color=imagecolorallocate($image,0,0,250);
$x1=150; $y1=120; $x2=250; $y2=210;
imageline($image,$x1,$y1,$x2,$y2,$line_color);
// JPEG image MIME(Multipurpose Internet Mail Extension) format
header (“Content-type: image/jpeg”);
// Output created image object as JPEG
imagejpeg($image);
// Cleanup all resources associated with an Image
imagedestroy($image);
?>
Copy and paste this code into your image creation program, then change parameters as you like.
To get this helpful tutorial to your PC – Download now.
Popularity: 51%

Leave a Reply