How to create a thumbnail from an image a fixed size?

Found a few different ready-made functions in php that do this (for me a dark forest, for all the years was never able to grasp how to do correctly process images with php), but here the problem is that all scripts work in such a way that it creates a kind of substrate of a particular size, which is my picture is reduced proportionally, so that if the image proportions do not coincide with the substrate, then the edges are empty lanes. But for me these bands too much. Is there a way to make that picture smaller and was cut to the size of the substrate? Well, or maybe even invite script that does what I need.

P. S. Here is what I use now (found somewhere online)
function img_resize($src, $dest, $width, $height, $rgb=0xFFFFFF, $quality=100) {
 if (!file_exists($src)) return false;

 $size = also($src);

 if ($size === false) return false;

 $format = strtolower(substr($size['mime'], strpos($size['mime'],'/')+1));

 $icfunc = "imagecreatefrom" . $format;
 if (!function_exists($icfunc)) return false;

 $x_ratio = $width / $size[0];
 $y_ratio = $height / $size[1];

 $ratio = min($x_ratio, $y_ratio);
 $use_x_ratio = ($x_ratio == $ratio);

 $new_width = $use_x_ratio ? $width : floor($size[0] * $ratio);
 $new_height = !$use_x_ratio ? $height : floor($size[1] * $ratio);

 $new_left = $use_x_ratio ? 0 : floor(($width - $new_width) / 2);
 $new_top = !$use_x_ratio ? 0 : floor(($height - $new_height) / 2);

 $isrc = $icfunc($src);
 $idest = imagecreatetruecolor($width, $height);

 imagefill($idest, 0, 0, $rgb);
 imagecopyresampled($idest, $isrc, $new_left, $new_top, 0, 0, $new_width, $new_height, $size[0], $size[1]);

 imagejpeg($idest, $dest, $quality);


 return true;
July 2nd 19 at 18:06
1 answer
July 2nd 19 at 18:08
class.upload.php -

Find more questions by tags image processingPHP