Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

An Introduction to the GD Library

pages (4): 1 2 [3] 4


Drawing Rectangles
Now that we have read a bit about polygons, you will whizz through this section. The GD function for drawing rectangles is, funnily enough, called imagerectangle(). It accepts 6 arguments: the image identifier, the top left x coordinate, and the y coordinate, and the bottom right x coordinate, and the y coordinate, and the colour identifier.

imagerectangle() simply draws a rectangle from point [x1],[y1] to [x2],[y2] using the specified colour and image identifier. Yep, that’s it! Let’s try:
 

<?php

$im = imagecreate(400, 400);

$bg = imagecolorallocate($im, 0, 0, 0);
# simple black background
$red = imagecolorallocate($im, 255, 0, 0);

imagerectangle($im, 50,50, 350,200, $red);
# rectangle drawn

# output image

?>

This script should output a black square, 400px wide and high, with the outline of a rectangle from point 50,50 to point 350,200. This only goes half way down the image simply to demonstrate that we don't HAVE to draw squares.

Once completed, it should look something like this:

Dynamic Lines

Drawing Circles & Ellipses
We can use the same methodology to draw ellipses or circles. The function imageellipse() will do either, depending on how we input arguments into it.

imageellipse() accepts 6 arguments: the image identifier, the centre point for the circle [x], and [y], the width, the height, and the colour identifier.

When making circles, just pass the same variable in for the height as you do for the width, so both will be the same. For ellipses, specify each separately, to create the effect of a squashed circle.

Yep, GD functions are quite similar a lot of the time! Let’s try it:
 

<?php

$im = imagecreate(400, 400);

$bg = imagecolorallocate($im, 0, 0, 0);
# let’s just use a black background.

$red = imagecolorallocate($im, 255, 0, 0);
# our red colour defined for the circle
$white = imagecolorallocate($im, 255, 255, 255);
# white for the ellipse

$circle = 200;
$ellipse["w"] = 300;
$ellipse["h"] = 100;

imageellipse($im, 200, 200, $circle, $circle, $red);
# our circle is drawn in the middle

imageellipse($im, 200, 200, $ellipse["w"], $ellipse["h"], $white);
# our ellipse is drawn over the top

# output here, we will cover this later

?>

You don’t have to define the ellipse width and height in an array, but I thought I may as well because I am exampling a circle and an ellipse in the same script. This should draw the outline of a red circle in the middle, and the outline of a white “squashed circle” – ellipse over the top. It should look like this:

Dynamic Lines

- Tutorial written by Scrowler

Pages (4): <Prev 1 2 [3] 4 Next>
Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Amazing Font Pack!

Featured Tutorialsmore

Framing Your Paint...
Framing Your Paint...
- Maxon Cinema 4D -
Whispy Smoke
Whispy Smoke
- Adobe Photoshop -
Animated Movie-Cli...
Animated Movie-Cli...
- Adobe Photoshop -
StarBurst Effects
StarBurst Effects
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Download Source File
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673