public function image_scale_cropped($source, $destination, $width, $height) { $info = ImageResize::image_get_info($source); // don't scale up if ($width > $info['width'] && $height > $info['height']) { return false; } /* If we are square. */ if (!$height || !$width || $height == $width) { if ($info['width'] > $info['height']) { $source_width = $source_height = $info['height']; $source_y = 0; $source_x = round(($info['width'] - $info['height']) / 2); } else { $source_width = $source_height = $info['width']; $source_x = 0; $source_y = round(($info['height'] - $info['width']) / 2); } if ($width) { $height = $width; } else { $width = $height; } /* We are not square. */ } else { $x_ratio = $width / $info['width']; $y_ratio = $height / $info['height']; if ($x_ratio * $info['width'] >= $width && $x_ratio * $info['height'] >= $height) { $aspect = $width / $height; $x_ratio * $info['width']; $source_width = $info['width']; $source_height = round($source_width / $aspect); $source_x = 0; $source_y = round(($info['height'] - $source_height) / 2); } else { $aspect = $height / $width; $source_height = $info['height']; $source_width = round($source_height / $aspect); $source_x = round(($info['width'] - $source_width) / 2); $source_y = 0; } } return ImageResize::image_gd_resize($source, $destination, $width, $height, $source_x, $source_y, $source_width, $source_height); }