I am able to crop the image as 500 x 500 px after uploading using php. But, the problem is the image is getting cropped if it is compressed. I want the full image to be compressed or resized in 500 x 500 without cropping. Please help. I am providing my code for reference.
function resize_image($file, $width, $height) {
list($w, $h) = getimagesize($file);
/* calculate new image size with ratio */
$ratio = max($width/$w, $height/$h);
$h = ceil($height / $ratio);
$x = ($w - $width / $ratio) / 2;
$w = ceil($width / $ratio);
/* read binary data from image file */
$imgString = file_get_contents($file);
/* create image from string */
$image = imagecreatefromstring($imgString);
$tmp = imagecreatetruecolor($width, $height);
imagecopyresampled($tmp, $image,
0, 0,
$x, 0,
$width, $height,
$w, $h);
$ext = pathinfo($file, PATHINFO_EXTENSION);
//$ext will be gif
imagejpeg($tmp, $file, 100);
return $file;
/* cleanup memory */
imagedestroy($image);
imagedestroy($tmp);
}