Part 2
Here finally is my GD guide part 2 sorry to anyone who has been waiting for it. If you have not yet read the first one i would suggest you do.
Image size
Now you can use GD to create a thumbnail or a smaller version of a image, but of course you don't want to have to guess image sizes or always change things. We can get the image size
PHP Code:
$imgName = $_GET["src"]; // get image name from URL under variable "src
$size = getimagesize("$imgName"); //get the image dimensions and place them in an array called size
PHP Code:
// Assign width and height of your image to variables
$imgName_w = $size[0];
$imgName_h = $size[1];
With the GD library you are able to copy from one image and place onto another image using the imagecopy(); function.
PHP Code:
imagecopy($newImage, $imgImport, $x, $imgName_h - $y - 1, $x, $y, 1, 1);
Properties
PHP Code:
$newImage //Destination image link resource
imgImport //Source image link resource
x //x-coordinate of destination point
$imgName_h - $y - 1 //y-coordinate of destination point
x //x-coordinate of source point
y // y-coordinate of source point
1 //Source width
1 //Source height
Lines & Shapes
We can create lines and other shapes in PHP. This allows us to create many nice looking effects like creating graphs or adding additional graphics to images dynamically.
The Lines
PHP Code:
imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
PHP Code:
image //An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
x1 // x-coordinate for first point
y1 //y-coordinate for first point
x2 // x-coordinate for second point
y2 //y-coordinate for second point
color // The line color. A color identifier created with imagecolorallocate()
http://img516.imageshack.us/img516/3374/explain1gu2.png
Results
http://img516.imageshack.us/img516/5...resultspz6.png
The Rectangles
You are able to create nice looking rectangles, but they can also look like squares.
PHP Code:
imagefilledrectangle ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color )
PHP Code:
image //An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
x1 //x-coordinate for point 1
y1 //y-coordinate for point 1
x2 //x-coordinate for point 2
y2 //y-coordinate for point 2
color //The fill color. A color identifier created with imagecolorallocate()
Result
http://img156.imageshack.us/img156/9...resultsbg6.png
They are some of the basic of shapes and the easiest. Next we shall be talking about Circles in the next chapter Part 3


Join the friendly bunch on IRC...