Fetch dimensions only once
This commit is contained in:
parent
0382ff970d
commit
f419888ec6
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue