PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Sep 22, 2018 12:59 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: cropping images with gd
PostPosted: Thu Jul 22, 2004 4:07 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jan 25, 2003 2:49 am
Posts: 1094
Which function in the gd library is used for cropping images? imagecopyresampled() ?

Would someone provide an example of using the function to crop an image ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 4:16 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
pass a source rect that differs from the image's dimensions.

Moved to Graphics


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 4:44 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jan 25, 2003 2:49 am
Posts: 1094
could you elaborate? I don't really even understand what some of the function args do.

Here is the function call i'm playing with trying to get the image cropped:
imagecopyresampled($im,$im, 0,0,0,0, 2*602,2*324, 602,324);

i'd like to crop an image that is 602*2 in width and 324*2 in height to a w/h of 602, 324.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 4:47 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jan 25, 2003 2:49 am
Posts: 1094
btw, am i using thr right function to crop?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 4:55 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
the code you are using will enlarge the image to 1204x648, not crop it.

cropping would be:
Syntax: [ Download ] [ Hide ]
imagecopyresampled($im,$im, 0,0, 0,0, 602,324, 602,324);



// or



imagecopyresampled($im,$im, 0,0, 301,127, 602,324, 602,324);


Quote:
bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:14 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jan 25, 2003 2:49 am
Posts: 1094
When I said I didn't even fully understand what all the arguments do I didn't mean to imply that I hadn't read the php.net manual on the function.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 5:16 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
I wasn't implying you hadn't.. just posting it for easier clarification. Your post said that the source image was 1204x648.. but you passed those as your destination request..


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 7:39 pm 
Offline
DevNet Resident
User avatar

Joined: Sat Jan 25, 2003 2:49 am
Posts: 1094
hey thanks, your examples helped me get imagecopyresampled() to crop for me now but which args do I change to alter the place where I crop?

like say I have an image and I want to get rid of everythign but a 10px square in the middle, how would I do something like that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 8:13 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
"src" prefixed ones will alter the location and dimenions copied from in the source image.
"dst" prefixed ones will alter the location and dimensions copied to in the destination image.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group