TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-02-2008, 09:42 PM   #1 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default The Big GD Guide - Part 2

I have posted this guide here as it uses images and for some reason the article system seems to be very limited when it comes to a editor like the forum one

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 
In order to access these measurements we can use the array and place them in variables of there own.

PHP Code:
// Assign width and height of your image to variables
$imgName_w $size[0];
$imgName_h $size[1]; 
Copy

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$y11); 

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 
Now that we have actually copied the image and placed it on the destination image.

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() 
As you can see we have 2 y cords and 2 x cords. Now this can be explained how these work using the diagram below.



Results



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



They are some of the basic of shapes and the easiest. Next we shall be talking about Circles in the next chapter Part 3
__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
The Following 2 Users Say Thank You to Rendair For This Useful Post:
Nor (03-07-2008), SaintIsaiah (06-08-2010)
Old 03-02-2008, 09:48 PM   #2 (permalink)
Alan @ CIT
Member of the Month
The Frequenter
Member of the Month Top Contributor 
 
Alan @ CIT's Avatar
 
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
Alan @ CIT is on a distinguished road
Default

Quote:
Originally Posted by Rendair View Post
I have posted this guide here as it uses images and for some reason the article system seems to be very limited when it comes to a editor like the forum one
Indeed, I end up having to link to all my images

Nice guide btw, looking forward to Part 3

Alan
Send a message via MSN to Alan @ CIT
Alan @ CIT is offline  
Reply With Quote
Old 03-05-2008, 04:14 AM   #3 (permalink)
Nor
The Addict
 
Join Date: Nov 2007
Posts: 282
Thanks: 61
Nor is on a distinguished road
Default

Yeah part three I'm looking for.
__________________
PHP/XHTML Freelancer:
Cleanscript.com v3 - Programming starting at just $5 act now!
Nor is offline  
Reply With Quote
Old 03-07-2008, 12:14 AM   #4 (permalink)
The Frequenter
 
Join Date: Dec 2007
Location: In my basement
Posts: 386
Thanks: 47
Aaron is on a distinguished road
Default

Jeeeeesus...

You really do plan this stuff out well, man. I really like this series of guides.

However, I have a few requests for the next couple of guides:
1) Explain the relation between coordinates and pixels, please O.o
2) If we use header(Content-type:image/png), how can GD be useful in lets say, a gallery, if it doesn't output more than an image?

3) Can you do a side-by-side of GD and the other image thing... Imagick?
Send a message via MSN to Aaron
Aaron is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:31 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design