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
https://forums.phpfreaks.com/topic/282371-help-with-imagecopyresampled/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.