I am not a very experienced PHP user, so i hope someone could help me with this.
I need a simple algorithm to crop a square section from a rectangular image. My code to do this looks like this:
$imagejpg = "img.jpg";
$img_orig = imagecreatefromjpeg($imagejpg);
$Sx = imagesx($img_orig);
$Sy = imagesy($img_orig);
$img_dest = imagecreatetruecolor($Sx,$Sy);
$dxy = ($Sx - $Sy)/2;
$srcX = $dxy;
$srcY = 0;
$dstX = 0;
$dstY = 0;
imagecopyresized($img_dest,$img_orig,$dstX,$dstY,$srcX,$srcY,$Sy,$Sy,$Sy,$Sy);
imageJPEG($img_dest);
which gives the square image i require, but the entire image width is still the same as the original and a big black chunk fills out the remainder of the space.
How do i make the image width the size of the cropped section?