how to crop image using gd ??

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to crop image using gd ??

Post by PHPycho »

First of all Hi to everybody......
I am again back with the new problem related to GD....
I have been given a task of image manipulation like cropping image.....

The scenario:
there are 4 input fields like x1,y1 ,x2,y2 for entering the starting point and the end point of croping of image. when the form is submitted then it should make a crop image on the /crop/ directory......

The problem:
I didnt got the idea ...of crop ...
I would be greatful if anybody help me in cropping images using four fields x1,y1,x2,y2..

Thank you in advance
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Hmmm, I wonder if you've searched google... check out imagecopyresampled()
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

Finally i was able to resize the image using the following code
but unable to crop the image..plz guide me....
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

All you need to do is create a new image (with imagecreate or imagecreatetruecolor ), and copy the area you want from the existing image to the new image using imagecopy. Easy.
Post Reply