Jump to content

Help with ImageCopyResampled


bmer

Recommended Posts

Hi, I'm a new to web development I and was hoping someone here can help me.

 

I'm trying to crop the middle part of a tall (or wide) picture in to a square.  My picture looks like this:

 

6cuy.png

 

 

I'd like to crop it's middle in to a square like this:

 

9bo9.png

 

 

Sadly, my pictures end up looking like this:

 

s731.jpg

 

 

Here's my PHP code that I am using:

 



if($OriginalHeight > $OriginalWidth){
   $StartY = $OriginalHeight / 4;
   $StartX = 0;
   $EndY = $StartY * 3;
   $EndX = $OriginalWidth;
}
 
 
if($OriginalHeight < $OriginalWidth){
   $StartY = 0;
   $StartX = $OriginalWidth / 4;
   $EndY = $OriginalHeight;
   $EndX = $StartX * 3;
}
 
 
if($OriginalHeight == $OriginalWidth){
   $StartY = 0;
   $StartX = $OriginalWidth;
   $EndY = $OriginalHeight;
   $EndX = $OriginalHeight;
}
 
imagecopyresampled($NewImage, $SrcImage, $EndX, $EndY, $StartX, $StartY, $NewImageSize, $NewImageSize, $OriginalWidth, $OriginalHeight);


 

PLease can you help me?  Thank you.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.