function resizeImage($source_image, $target_image, $width = 0, $height = 0, $best_fit = false)
{
$SimpleImage = new SimpleImage($source_image);
if ($best_fit) {
$SimpleImage->best_fit($width, $height)->save($target_image, 100);
} else {
if (!$width && !$height) {
$SimpleImage->save($target_image);
} elseif ($SimpleImage->get_width() >= $width) {
$SimpleImage->fit_to_width($width)->crop(0, 0, $width, $SimpleImage->get_height() > $height ? $height : $SimpleImage->get_height())->save($target_image);
} elseif ($SimpleImage->get_height() >= $height) {
$SimpleImage->fit_to_width($height)->crop(0, 0, $SimpleImage->get_width() > $width ? $width : $SimpleImage->get_width(), $height)->save($target_image);
} else {
$SimpleImage->best_fit($width, $height)->save($target_image);
}
}
}