1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 09:52:59 +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) public function fit(Size $size)
{ {
$auto_width = clone $size;
$auto_height = clone $size;
// create size with auto width
$auto_width->resize(null, $this->height, function ($constraint) {
$constraint->aspectRatio();
});
// create size with auto height // create size with auto height
$auto_height = clone $size;
$auto_height->resize($this->width, null, function ($constraint) { $auto_height->resize($this->width, null, function ($constraint) {
$constraint->aspectRatio(); $constraint->aspectRatio();
}); });
// decide which version to use // decide which version to use
if ($auto_height->fitsInto($this)) { if ($auto_height->fitsInto($this)) {
$size = $auto_height; $size = $auto_height;
} else { } else {
// create size with auto width
$auto_width = clone $size;
$auto_width->resize(null, $this->height, function ($constraint) {
$constraint->aspectRatio();
});
$size = $auto_width; $size = $auto_width;
} }