The task is not to cut the edges to size 900-100, and compress.
My code just cuts it off but it doesn't quite fit
public function smart_resize($file_input, $file_output, $_w, $_h, $min_w = 100, $min_h = 100) { $getimagesize = getimagesize($file_input); if (($_w==$min_w) && ($_h == $min_h)) { $width = $min_w; $height = $min_h; } else if (($getimagesize[0]>$_w) && ($getimagesize[1]>$_h)) { $width = $_w; $height = $_h; } else if (($getimagesize[0]>=$_w) && ($getimagesize[1]<$_h)) { $width = $_w; $height = ($width/($getimagesize[0]/$getimagesize[1])); } else if (($getimagesize[0]<$_w) && ($getimagesize[1]>$_h)) { $height = $_h; $width = ($height/($getimagesize[1]/$getimagesize[0])); } else { $height = $getimagesize[1]; $width = $getimagesize[0]; } if (($width<$min_w) || ($height<$min_h)) { return 'error'; } $_w = $width; $_h = $height; $w_o = $_w; $h_o = null; list($w_i, $h_i, $type) = getimagesize($file_input); $types = array('jpg','gif','jpeg','png'); $ext = $types[$type]; if ($ext) { $func = 'imagecreatefrom'.$ext; $img = $func($file_input); } if (($w_o/($w_i/$h_i))<$_h) { $h_o = $_h; $w_o = null; } if (!$h_o) { $h_o = $w_o/($w_i/$h_i); } if (!$w_o) { $w_o = $h_o/($h_i/$w_i); } $img_o = imagecreatetruecolor($w_o, $h_o); imageAlphaBlending($img_o,false); imageSaveAlpha($img_o,true); imagecopyresampled($img_o, $img, 0, 0, 0, 0, $w_o, $h_o, $w_i, $h_i); if ($h_o<$_h) { $_img_o = imagecreatetruecolor($_w, $_h); imageAlphaBlending($_img_o,false); imageSaveAlpha($_img_o,true); $src_x = (($_w/2)-($w_o/2)); $src_y = (($_h/2)-($_h/2)); imagecopy($_img_o, $img_o, 0, 0, $src_x, $src_y, $_w, $_h); imagejpeg($_img_o, ($file_output? $file_output : null), 90); imagedestroy($img_o); } else if ($h_o>=$_h) { $_img_o = imagecreatetruecolor($_w, $_h); imageAlphaBlending($_img_o,false); imageSaveAlpha($_img_o,true); $src_x = (($w_o/2)-($_w/2)); $src_y = (($h_o/2)-($_h/2)); imagecopy($_img_o, $img_o, 0, 0, $src_x, $src_y, $_w, $_h); imagejpeg($_img_o, ($file_output? $file_output : null), 90); imagedestroy($img_o); } else { imagejpeg($img_o, ($file_output? $file_output : null), 90); imagedestroy($img_o); } }