function SquareImage($imgSrc, $imgDes, $thumbSize = 1000){
list($width, $height) = getimagesize($imgSrc);
$myImage = imagecreatefromjpeg($imgSrc);
if ($width > $height) {
$y = 0;
$x = ($width - $height) / 2;
$smallestSide = $height;
} else {
$x = 0;
$y = ($height - $width) / 2;
$smallestSide = $width;
}
$thumb = imagecreatetruecolor($thumbSize, $thumbSize);
imagecopyresampled($thumb, $myImage, 0, 0, $x, $y, $thumbSize, $thumbSize, $smallestSide, $smallestSide);
if (file_exists($imgSrc)) {
unlink($imgSrc);
}
imagejpeg($thumb, $imgDes, 100);
@imagedestroy($myImage);
@imagedestroy($thumb);
}