From f419888ec699c477aae1a30314621abadd3a7cf8 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 15 Feb 2022 17:46:29 +0100 Subject: [PATCH] Fetch dimensions only once --- classes/ImageResizer.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/classes/ImageResizer.php b/classes/ImageResizer.php index 6faa6eb..9d02241 100644 --- a/classes/ImageResizer.php +++ b/classes/ImageResizer.php @@ -60,20 +60,21 @@ class ImageResizer { $return = collect([]); $ratios = collect(); - $ratios->push($this->dimensions()); + $dimensions = $this->dimensions(); + $ratios->push($dimensions); $ratios = $ratios->merge($this->sizes()); - foreach (collect(Setting::get('breakpoints'))->push($this->dimensions()->get('width'))->unique() as $size) { + foreach (collect(Setting::get('breakpoints'))->push($dimensions->get('width'))->unique() as $size) { foreach ($ratios as $ratio) { $width = $size; $height = $size * $ratio->get('height') / $ratio->get('width'); - if ($height > $this->dimensions()->get('height')) { - $width = $width * $this->dimensions()->get('height') / $height; - $height = $this->dimensions()->get('height'); + if ($height > $dimensions->get('height')) { + $width = $width * $dimensions->get('height') / $height; + $height = $dimensions->get('height'); } - if (ceil($width) > $this->dimensions()->get('width') || ceil($height) > $this->dimensions()->get('height')) { + if (ceil($width) > $dimensions->get('width') || ceil($height) > $dimensions->get('height')) { continue; }