From d8dacc65464c8902c1477b2eb246eb2c5f2db619 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 9 Nov 2021 01:51:19 +0100 Subject: [PATCH] Fixed: Order sizes from top to bottom --- classes/TagGenerator.php | 3 +++ tests/ImageTagTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/classes/TagGenerator.php b/classes/TagGenerator.php index 950c702..0f7f280 100644 --- a/classes/TagGenerator.php +++ b/classes/TagGenerator.php @@ -128,6 +128,9 @@ class TagGenerator { $sizes = collect(explode('|', $sizes)); $minSize = $sizes->shift(); + $sizes = $sizes->sortByDesc(function($size) { + return explode(':', $size)[0]; + }); return $sizes->map(function($size) { $components = explode(':', $size); diff --git a/tests/ImageTagTest.php b/tests/ImageTagTest.php index bda3648..a576886 100644 --- a/tests/ImageTagTest.php +++ b/tests/ImageTagTest.php @@ -181,7 +181,7 @@ class ImageTagTest extends TestCase $output = app(Twig::class)->parse('{{ "/pages/test.jpg" | resize("original", "1rem|200:10px|500:20px") }}'); - $this->assertStringContainsString('sizes="(min-width: 200px) 10px, (min-width: 500px) 20px, 1rem"', $output); + $this->assertStringContainsString('sizes="(min-width: 500px) 20px, (min-width: 200px) 10px, 1rem"', $output); } public function testItGeneratesOnlySingleImage()