bmer Posted September 23, 2013 Share Posted September 23, 2013 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: I'd like to crop it's middle in to a square like this: Sadly, my pictures end up looking like this: 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 More sharing options...
vinny42 Posted September 23, 2013 Share Posted September 23, 2013 Check your coordinates. The destination coordinates in the new image should be 0,0 to place the pasting action at the top-left corner. Link to comment https://forums.phpfreaks.com/topic/282371-help-with-imagecopyresampled/#findComment-1450755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.