1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 01:51:43 +02:00

more efficient fitting

This commit is contained in:
Oliver Vogel
2014-05-12 15:51:37 +02:00
parent 772425e3ce
commit 7d8bdd61d1

View File

@@ -109,23 +109,27 @@ class Size
public function fit(Size $size)
{
$auto_width = clone $size;
// create size with auto height
$auto_height = clone $size;
// create size with auto width
$auto_width->resize(null, $this->height, function ($constraint) {
$constraint->aspectRatio();
});
// create size with auto height
$auto_height->resize($this->width, null, function ($constraint) {
$constraint->aspectRatio();
});
// decide which version to use
if ($auto_height->fitsInto($this)) {
$size = $auto_height;
} else {
// create size with auto width
$auto_width = clone $size;
$auto_width->resize(null, $this->height, function ($constraint) {
$constraint->aspectRatio();
});
$size = $auto_width;
}