public function resizeToBestFit($max_width, $max_height, $allow_enlarge = false)
{
if ($this->getSourceWidth() <= $max_width && $this->getSourceHeight() <= $max_height && $allow_enlarge === false) {
return $this;
}
$ratio = $this->getSourceHeight() / $this->getSourceWidth();
$width = $max_width;
$height = $width * $ratio;
if ($height > $max_height) {
$height = $max_height;
$width = $height / $ratio;
}
return $this->resize($width, $height, $allow_enlarge);
}
protected function makeThumb($file, MediaProvider $media) { $name = 'thumb-' . $media->file; $new = $media->path . '/' . $name; $image = new ImageResize($file); $image->resizeToBestFit(150, 150); $image->save(storage_path() . $new); return $name; }