Hi, I’m a beginner to PHP and was hoping an expert could help me.
I would like to crop the central part of a long image in to a square. I have an image that looks like this:
Img51.imageshack.us/img51/5335/6cuy.png
I would like to crop it’s center in to a square like this:
img854.imageshack.us/img854/5963/9bo9.png
However, my images are turning out like this:
img202.imageshack.us/img202/6073/s731.jpg
Here is the PHP code that I am using but am having no luck whatsoever:
[php]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);[/php]
PLease can you help me? Thank you.