From 368991c403997a524e388d7e9d577f83c47e4906 Mon Sep 17 00:00:00 2001 From: Falk Berger Date: Thu, 23 May 2019 11:01:40 +0200 Subject: [PATCH 1/5] Support for min/maxHeight added --- Classes/Utility/ResponsiveImagesUtility.php | 22 ++++++++++++++++----- Classes/ViewHelpers/ImageViewHelper.php | 6 ++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Classes/Utility/ResponsiveImagesUtility.php b/Classes/Utility/ResponsiveImagesUtility.php index f96837f..c730da3 100644 --- a/Classes/Utility/ResponsiveImagesUtility.php +++ b/Classes/Utility/ResponsiveImagesUtility.php @@ -88,6 +88,7 @@ public function createImageTagWithSrcset( // Use width of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); + $referenceHeight = $fallbackImage->getProperty('height'); // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; @@ -97,7 +98,7 @@ public function createImageTagWithSrcset( } // Generate different image sizes for srcset attribute - $srcsetImages = $this->generateSrcsetImages($originalImage, $referenceWidth, $srcset, $cropArea, $absoluteUri); + $srcsetImages = $this->generateSrcsetImages($originalImage, $referenceWidth, $referenceHeight, $srcset, $cropArea, $absoluteUri); $srcsetMode = substr(key($srcsetImages), -1); // x or w // Add fallback image to source options @@ -114,7 +115,7 @@ public function createImageTagWithSrcset( // Provide image dimensions to be consistent with TYPO3 core behavior $tag->addAttribute('width', $referenceWidth); - $tag->addAttribute('height', $fallbackImage->getProperty('height')); + $tag->addAttribute('height', $referenceHeight); // Add metadata to image tag $this->addMetadataToImageTag($tag, $originalImage, $fallbackImage, $focusArea); @@ -170,9 +171,10 @@ public function createPictureTag( // Normalize breakpoint configuration $breakpoints = $this->normalizeImageBreakpoints($breakpoints); - // Use width of fallback image as reference for relative sizes (1x, 2x...) + // Use width and height of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); - + $referenceHeight = $fallbackImage->getProperty('height'); + // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; @@ -184,6 +186,7 @@ public function createPictureTag( $srcset = $this->generateSrcsetImages( $originalImage, $referenceWidth, + $referenceHeight, $lastBreakpoint['srcset'], $cropArea, $absoluteUri @@ -225,6 +228,7 @@ public function createPictureTag( $sourceTag = $this->createPictureSourceTag( $originalImage, $referenceWidth, + $referenceHeight, $breakpoint['srcset'], $breakpoint['media'], $breakpoint['sizes'], @@ -248,6 +252,7 @@ public function createPictureTag( * * @param FileInterface $originalImage * @param int $defaultWidth + * @param int $defaultHeight * @param array|string $srcset * @param string $mediaQuery * @param string $sizesQuery @@ -260,6 +265,7 @@ public function createPictureTag( public function createPictureSourceTag( FileInterface $originalImage, int $defaultWidth, + int $defaultHeight, $srcset, string $mediaQuery = '', string $sizesQuery = '', @@ -273,7 +279,7 @@ public function createPictureSourceTag( $attributePrefix = $lazyload ? 'data-' : ''; // Generate different image sizes for srcset attribute - $srcsetImages = $this->generateSrcsetImages($originalImage, $defaultWidth, $srcset, $cropArea, $absoluteUri); + $srcsetImages = $this->generateSrcsetImages($originalImage, $defaultWidth, $defaultHeight, $srcset, $cropArea, $absoluteUri); $srcsetMode = substr(key($srcsetImages), -1); // x or w // Create source tag for this breakpoint @@ -377,6 +383,7 @@ public function addMetadataToImageTag( * * @param FileInterface $image * @param int $defaultWidth + * @param int $defaultHeight * @param array|string $srcset * @param Area $cropArea * @param bool $absoluteUri @@ -386,6 +393,7 @@ public function addMetadataToImageTag( public function generateSrcsetImages( FileInterface $image, int $defaultWidth, + int $defaultHeight, $srcset, Area $cropArea = null, bool $absoluteUri = false @@ -404,14 +412,17 @@ public function generateSrcsetImages( switch ($srcsetMode) { case 'x': $candidateWidth = (int) ($defaultWidth * (float) substr($widthDescriptor, 0, -1)); + $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); break; case 'w': $candidateWidth = (int) substr($widthDescriptor, 0, -1); + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); break; default: $candidateWidth = (int) $widthDescriptor; + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); $srcsetMode = 'w'; $widthDescriptor = $candidateWidth . 'w'; } @@ -419,6 +430,7 @@ public function generateSrcsetImages( // Generate image $processingInstructions = [ 'width' => $candidateWidth, + 'height' => $candidateHeight, 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), ]; $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions); diff --git a/Classes/ViewHelpers/ImageViewHelper.php b/Classes/ViewHelpers/ImageViewHelper.php index 97f76ca..b7e80ee 100644 --- a/Classes/ViewHelpers/ImageViewHelper.php +++ b/Classes/ViewHelpers/ImageViewHelper.php @@ -102,6 +102,12 @@ public function render() if (!is_null($this->arguments['maxWidth'])) { $processingInstructions['maxWidth'] = $this->arguments['maxWidth']; } + if (!is_null($this->arguments['minHeight'])) { + $processingInstructions['minHeight'] = $this->arguments['minHeight']; + } + if (!is_null($this->arguments['maxHeight'])) { + $processingInstructions['maxHeight'] = $this->arguments['maxHeight']; + } $fallbackImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions); if ($this->arguments['breakpoints']) { From abd4d99858624d08af0a882ffbedcd3ee9e7f44b Mon Sep 17 00:00:00 2001 From: Falk Berger Date: Wed, 5 Jun 2019 11:48:49 +0200 Subject: [PATCH 2/5] Modified Tests for additional height parameter --- Classes/Utility/ResponsiveImagesUtility.php | 22 +++++++++++++---- .../ResponsiveImagesUtility/HelpersTest.php | 24 ++++++++++++------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Classes/Utility/ResponsiveImagesUtility.php b/Classes/Utility/ResponsiveImagesUtility.php index f96837f..b217d69 100644 --- a/Classes/Utility/ResponsiveImagesUtility.php +++ b/Classes/Utility/ResponsiveImagesUtility.php @@ -88,6 +88,7 @@ public function createImageTagWithSrcset( // Use width of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); + $referenceHeight = $fallbackImage->getProperty('height'); // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; @@ -97,7 +98,7 @@ public function createImageTagWithSrcset( } // Generate different image sizes for srcset attribute - $srcsetImages = $this->generateSrcsetImages($originalImage, $referenceWidth, $srcset, $cropArea, $absoluteUri); + $srcsetImages = $this->generateSrcsetImages($originalImage, $referenceWidth, $referenceHeight, $srcset, $cropArea, $absoluteUri); $srcsetMode = substr(key($srcsetImages), -1); // x or w // Add fallback image to source options @@ -114,7 +115,7 @@ public function createImageTagWithSrcset( // Provide image dimensions to be consistent with TYPO3 core behavior $tag->addAttribute('width', $referenceWidth); - $tag->addAttribute('height', $fallbackImage->getProperty('height')); + $tag->addAttribute('height', $referenceHeight); // Add metadata to image tag $this->addMetadataToImageTag($tag, $originalImage, $fallbackImage, $focusArea); @@ -170,9 +171,10 @@ public function createPictureTag( // Normalize breakpoint configuration $breakpoints = $this->normalizeImageBreakpoints($breakpoints); - // Use width of fallback image as reference for relative sizes (1x, 2x...) + // Use width and height of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); - + $referenceHeight = $fallbackImage->getProperty('height'); + // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; @@ -184,6 +186,7 @@ public function createPictureTag( $srcset = $this->generateSrcsetImages( $originalImage, $referenceWidth, + $referenceHeight, $lastBreakpoint['srcset'], $cropArea, $absoluteUri @@ -225,6 +228,7 @@ public function createPictureTag( $sourceTag = $this->createPictureSourceTag( $originalImage, $referenceWidth, + $referenceHeight, $breakpoint['srcset'], $breakpoint['media'], $breakpoint['sizes'], @@ -248,6 +252,7 @@ public function createPictureTag( * * @param FileInterface $originalImage * @param int $defaultWidth + * @param int $defaultHeight * @param array|string $srcset * @param string $mediaQuery * @param string $sizesQuery @@ -260,6 +265,7 @@ public function createPictureTag( public function createPictureSourceTag( FileInterface $originalImage, int $defaultWidth, + int $defaultHeight, $srcset, string $mediaQuery = '', string $sizesQuery = '', @@ -273,7 +279,7 @@ public function createPictureSourceTag( $attributePrefix = $lazyload ? 'data-' : ''; // Generate different image sizes for srcset attribute - $srcsetImages = $this->generateSrcsetImages($originalImage, $defaultWidth, $srcset, $cropArea, $absoluteUri); + $srcsetImages = $this->generateSrcsetImages($originalImage, $defaultWidth, $defaultHeight, $srcset, $cropArea, $absoluteUri); $srcsetMode = substr(key($srcsetImages), -1); // x or w // Create source tag for this breakpoint @@ -377,6 +383,7 @@ public function addMetadataToImageTag( * * @param FileInterface $image * @param int $defaultWidth + * @param int $defaultHeight * @param array|string $srcset * @param Area $cropArea * @param bool $absoluteUri @@ -386,6 +393,7 @@ public function addMetadataToImageTag( public function generateSrcsetImages( FileInterface $image, int $defaultWidth, + int $defaultHeight, $srcset, Area $cropArea = null, bool $absoluteUri = false @@ -404,14 +412,17 @@ public function generateSrcsetImages( switch ($srcsetMode) { case 'x': $candidateWidth = (int) ($defaultWidth * (float) substr($widthDescriptor, 0, -1)); + $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); break; case 'w': $candidateWidth = (int) substr($widthDescriptor, 0, -1); + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); break; default: $candidateWidth = (int) $widthDescriptor; + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); $srcsetMode = 'w'; $widthDescriptor = $candidateWidth . 'w'; } @@ -419,6 +430,7 @@ public function generateSrcsetImages( // Generate image $processingInstructions = [ 'width' => $candidateWidth, + 'height' => $candidateHeight, 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), ]; $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions); diff --git a/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php b/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php index 56cdcea..893880e 100644 --- a/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php +++ b/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php @@ -120,7 +120,8 @@ public function generatesSrcsetImagesProvider() return [ // Test high dpi image srcset 'usingHighDpi' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, ['1x', '2x'], null, @@ -129,7 +130,8 @@ public function generatesSrcsetImagesProvider() ], // Test responsive image srcset (widths in integers) 'usingResponsiveWidths' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, [200, 400, 600], null, @@ -138,7 +140,8 @@ public function generatesSrcsetImagesProvider() ], // Test responsive image srcset (widths as strings) 'usingResponsiveWidthsAsStrings' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, ['200w', '400w', '600w'], null, @@ -147,7 +150,8 @@ public function generatesSrcsetImagesProvider() ], // Test absolute urls 'requestingAbsoluteUrls' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, ['200w', '400w', '600w'], null, @@ -160,7 +164,8 @@ public function generatesSrcsetImagesProvider() ], // Test srcset input as string 'usingSrcsetString' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, '200, 400, 600', null, @@ -172,7 +177,8 @@ public function generatesSrcsetImagesProvider() ] ], 'usingTooSmallImage' => [ - $this->mockFileObject(['width' => 400, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 400, 'height' => 400, 'extension' => 'jpg']), + 400, 400, '200, 300, 500', null, @@ -185,7 +191,8 @@ public function generatesSrcsetImagesProvider() ], // Test if special characters are kept in file name 'usingSpecialCharactersInFileName' => [ - $this->mockFileObject(['name' => 'this/is a/filename@with-/special!charac,ters', 'width' => 400, 'extension' => 'jpg']), + $this->mockFileObject(['name' => 'this/is a/filename@with-/special!charac,ters', 'width' => 400, 'height' => 400, 'extension' => 'jpg']), + 400, 400, [200], null, @@ -201,13 +208,14 @@ public function generatesSrcsetImagesProvider() * @test * @dataProvider generatesSrcsetImagesProvider */ - public function generatesSrcsetImages($originalImage, $width, $srcsetConfig, $cropArea, $absoluteUri, $output) + public function generatesSrcsetImages($originalImage, $width, $height, $srcsetConfig, $cropArea, $absoluteUri, $output) { $this->assertEquals( $output, $this->utility->generateSrcsetImages( $originalImage, $width, + $height, $srcsetConfig, $cropArea, $absoluteUri From 03a06c1298d535d7f5d81f0161b121dab38fb364 Mon Sep 17 00:00:00 2001 From: Falk Berger Date: Wed, 5 Jun 2019 12:09:39 +0200 Subject: [PATCH 3/5] Fixes for linter and phpunit failures --- Classes/Utility/ResponsiveImagesUtility.php | 2 +- .../ResponsiveImagesUtility/PictureSourceTagTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Classes/Utility/ResponsiveImagesUtility.php b/Classes/Utility/ResponsiveImagesUtility.php index b217d69..5f20ea4 100644 --- a/Classes/Utility/ResponsiveImagesUtility.php +++ b/Classes/Utility/ResponsiveImagesUtility.php @@ -174,7 +174,7 @@ public function createPictureTag( // Use width and height of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); $referenceHeight = $fallbackImage->getProperty('height'); - + // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; diff --git a/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php b/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php index 02171ff..01e26e5 100644 --- a/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php +++ b/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php @@ -11,6 +11,7 @@ public function createPictureSourceTagProvider() 'usingEmptySrcset' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 1000, [], '', '', @@ -22,6 +23,7 @@ public function createPictureSourceTagProvider() 'usingHighDpi' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 1000, ['1x', '2x'], '', '', @@ -33,6 +35,7 @@ public function createPictureSourceTagProvider() 'usingResponsiveWidths' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 1000, [400, 800], '', '', @@ -44,6 +47,7 @@ public function createPictureSourceTagProvider() 'usingDynamicSizesQuery' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 1000, [400], 'media query', '%d', @@ -55,6 +59,7 @@ public function createPictureSourceTagProvider() 'requestingAbsoluteUrls' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 1000, ['1x', '2x'], '', '', @@ -72,6 +77,7 @@ public function createPictureSourceTagProvider() public function createPictureSourceTag( $image, $defaultWidth, + $defaultHeight, $srcset, $mediaQuery, $sizesQuery, @@ -82,6 +88,7 @@ public function createPictureSourceTag( $tag = $this->utility->createPictureSourceTag( $image, $defaultWidth, + $defaultHeight, $srcset, $mediaQuery, $sizesQuery, From 43265060c4691010592baa0a0be4e85bb85b2929 Mon Sep 17 00:00:00 2001 From: Falk Berger Date: Fri, 21 Jun 2019 12:47:58 +0200 Subject: [PATCH 4/5] min/max-Width/Height only for srcset The min/max dimensions are used only for images with srcset and no breakpoints. --- Classes/Utility/ResponsiveImagesUtility.php | 27 ++++++++++++------- .../ResponsiveImagesUtility/HelpersTest.php | 24 +++++++++++------ .../PictureSourceTagTest.php | 7 +++++ 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Classes/Utility/ResponsiveImagesUtility.php b/Classes/Utility/ResponsiveImagesUtility.php index c730da3..aa76d35 100644 --- a/Classes/Utility/ResponsiveImagesUtility.php +++ b/Classes/Utility/ResponsiveImagesUtility.php @@ -171,10 +171,9 @@ public function createPictureTag( // Normalize breakpoint configuration $breakpoints = $this->normalizeImageBreakpoints($breakpoints); - // Use width and height of fallback image as reference for relative sizes (1x, 2x...) + // Use width of fallback image as reference for relative sizes (1x, 2x...) $referenceWidth = $fallbackImage->getProperty('width'); - $referenceHeight = $fallbackImage->getProperty('height'); - + // if lazyload enabled add data- prefix $attributePrefix = $lazyload ? 'data-' : ''; @@ -186,7 +185,7 @@ public function createPictureTag( $srcset = $this->generateSrcsetImages( $originalImage, $referenceWidth, - $referenceHeight, + 0, $lastBreakpoint['srcset'], $cropArea, $absoluteUri @@ -228,7 +227,7 @@ public function createPictureTag( $sourceTag = $this->createPictureSourceTag( $originalImage, $referenceWidth, - $referenceHeight, + 0, $breakpoint['srcset'], $breakpoint['media'], $breakpoint['sizes'], @@ -383,7 +382,7 @@ public function addMetadataToImageTag( * * @param FileInterface $image * @param int $defaultWidth - * @param int $defaultHeight + * @param int $defaultHeight - if value is zero, this value is not used and dimensions from cropping configuration are used * @param array|string $srcset * @param Area $cropArea * @param bool $absoluteUri @@ -412,17 +411,23 @@ public function generateSrcsetImages( switch ($srcsetMode) { case 'x': $candidateWidth = (int) ($defaultWidth * (float) substr($widthDescriptor, 0, -1)); - $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); + if ($defaultHeight > 0) { + $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); + } break; case 'w': $candidateWidth = (int) substr($widthDescriptor, 0, -1); - $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); + if ($defaultHeight > 0) { + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); + } break; default: $candidateWidth = (int) $widthDescriptor; - $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); + if ($defaultHeight > 0) { + $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); + } $srcsetMode = 'w'; $widthDescriptor = $candidateWidth . 'w'; } @@ -430,9 +435,11 @@ public function generateSrcsetImages( // Generate image $processingInstructions = [ 'width' => $candidateWidth, - 'height' => $candidateHeight, 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), ]; + if ($defaultHeight > 0) { + $processingInstructions['height'] = $candidateHeight; + } $processedImage = $this->imageService->applyProcessingInstructions($image, $processingInstructions); // If processed file isn't as wide as it should be ([GFX][processor_allowUpscaling] set to false) diff --git a/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php b/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php index 56cdcea..73f5bc2 100644 --- a/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php +++ b/Tests/Unit/Utility/ResponsiveImagesUtility/HelpersTest.php @@ -120,8 +120,9 @@ public function generatesSrcsetImagesProvider() return [ // Test high dpi image srcset 'usingHighDpi' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), 400, + 0, ['1x', '2x'], null, false, @@ -129,8 +130,9 @@ public function generatesSrcsetImagesProvider() ], // Test responsive image srcset (widths in integers) 'usingResponsiveWidths' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), 400, + 0, [200, 400, 600], null, false, @@ -138,7 +140,8 @@ public function generatesSrcsetImagesProvider() ], // Test responsive image srcset (widths as strings) 'usingResponsiveWidthsAsStrings' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, ['200w', '400w', '600w'], null, @@ -147,7 +150,8 @@ public function generatesSrcsetImagesProvider() ], // Test absolute urls 'requestingAbsoluteUrls' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), + 400, 400, ['200w', '400w', '600w'], null, @@ -160,8 +164,9 @@ public function generatesSrcsetImagesProvider() ], // Test srcset input as string 'usingSrcsetString' => [ - $this->mockFileObject(['width' => 1000, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 1000, 'height' => 1000, 'extension' => 'jpg']), 400, + 200, '200, 400, 600', null, true, @@ -172,8 +177,9 @@ public function generatesSrcsetImagesProvider() ] ], 'usingTooSmallImage' => [ - $this->mockFileObject(['width' => 400, 'extension' => 'jpg']), + $this->mockFileObject(['width' => 400, 'height' => 400, 'extension' => 'jpg']), 400, + 200, '200, 300, 500', null, false, @@ -185,8 +191,9 @@ public function generatesSrcsetImagesProvider() ], // Test if special characters are kept in file name 'usingSpecialCharactersInFileName' => [ - $this->mockFileObject(['name' => 'this/is a/filename@with-/special!charac,ters', 'width' => 400, 'extension' => 'jpg']), + $this->mockFileObject(['name' => 'this/is a/filename@with-/special!charac,ters', 'width' => 400, 'height' => 400, 'extension' => 'jpg']), 400, + 200, [200], null, false, @@ -201,13 +208,14 @@ public function generatesSrcsetImagesProvider() * @test * @dataProvider generatesSrcsetImagesProvider */ - public function generatesSrcsetImages($originalImage, $width, $srcsetConfig, $cropArea, $absoluteUri, $output) + public function generatesSrcsetImages($originalImage, $width, $height, $srcsetConfig, $cropArea, $absoluteUri, $output) { $this->assertEquals( $output, $this->utility->generateSrcsetImages( $originalImage, $width, + $height, $srcsetConfig, $cropArea, $absoluteUri diff --git a/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php b/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php index 02171ff..7d7b66f 100644 --- a/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php +++ b/Tests/Unit/Utility/ResponsiveImagesUtility/PictureSourceTagTest.php @@ -11,6 +11,7 @@ public function createPictureSourceTagProvider() 'usingEmptySrcset' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 0, [], '', '', @@ -22,6 +23,7 @@ public function createPictureSourceTagProvider() 'usingHighDpi' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 0, ['1x', '2x'], '', '', @@ -33,6 +35,7 @@ public function createPictureSourceTagProvider() 'usingResponsiveWidths' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 0, [400, 800], '', '', @@ -44,6 +47,7 @@ public function createPictureSourceTagProvider() 'usingDynamicSizesQuery' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 0, [400], 'media query', '%d', @@ -55,6 +59,7 @@ public function createPictureSourceTagProvider() 'requestingAbsoluteUrls' => [ $this->mockFileObject(['width' => 2000, 'height' => 2000, 'extension' => 'jpg']), 1000, + 0, ['1x', '2x'], '', '', @@ -72,6 +77,7 @@ public function createPictureSourceTagProvider() public function createPictureSourceTag( $image, $defaultWidth, + $defaultHeight, $srcset, $mediaQuery, $sizesQuery, @@ -82,6 +88,7 @@ public function createPictureSourceTag( $tag = $this->utility->createPictureSourceTag( $image, $defaultWidth, + $defaultHeight, $srcset, $mediaQuery, $sizesQuery, From 90a217ae6ac62ef63e8b1f936df9cd0fd980d7aa Mon Sep 17 00:00:00 2001 From: Falk Berger Date: Fri, 21 Jun 2019 13:26:40 +0200 Subject: [PATCH 5/5] Removed merge conflicts --- Classes/Utility/ResponsiveImagesUtility.php | 24 --------------------- 1 file changed, 24 deletions(-) diff --git a/Classes/Utility/ResponsiveImagesUtility.php b/Classes/Utility/ResponsiveImagesUtility.php index ee7e465..21655f2 100644 --- a/Classes/Utility/ResponsiveImagesUtility.php +++ b/Classes/Utility/ResponsiveImagesUtility.php @@ -186,11 +186,7 @@ public function createPictureTag( $srcset = $this->generateSrcsetImages( $originalImage, $referenceWidth, -<<<<<<< HEAD - $referenceHeight, -======= 0, ->>>>>>> refs/heads/feature/minMaxHeight $lastBreakpoint['srcset'], $cropArea, $absoluteUri @@ -232,11 +228,7 @@ public function createPictureTag( $sourceTag = $this->createPictureSourceTag( $originalImage, $referenceWidth, -<<<<<<< HEAD - $referenceHeight, -======= 0, ->>>>>>> refs/heads/feature/minMaxHeight $breakpoint['srcset'], $breakpoint['media'], $breakpoint['sizes'], @@ -391,11 +383,7 @@ public function addMetadataToImageTag( * * @param FileInterface $image * @param int $defaultWidth -<<<<<<< HEAD - * @param int $defaultHeight -======= * @param int $defaultHeight - if value is zero, this value is not used and dimensions from cropping configuration are used ->>>>>>> refs/heads/feature/minMaxHeight * @param array|string $srcset * @param Area $cropArea * @param bool $absoluteUri @@ -424,35 +412,23 @@ public function generateSrcsetImages( switch ($srcsetMode) { case 'x': $candidateWidth = (int) ($defaultWidth * (float) substr($widthDescriptor, 0, -1)); -<<<<<<< HEAD - $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); -======= if ($defaultHeight > 0) { $candidateHeight = (int) ($defaultHeight * (float) substr($widthDescriptor, 0, -1)); } ->>>>>>> refs/heads/feature/minMaxHeight break; case 'w': $candidateWidth = (int) substr($widthDescriptor, 0, -1); -<<<<<<< HEAD - $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); -======= if ($defaultHeight > 0) { $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); } ->>>>>>> refs/heads/feature/minMaxHeight break; default: $candidateWidth = (int) $widthDescriptor; -<<<<<<< HEAD - $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); -======= if ($defaultHeight > 0) { $candidateHeight = (int) ($candidateWidth * $defaultHeight / $defaultWidth + 0.5); } ->>>>>>> refs/heads/feature/minMaxHeight $srcsetMode = 'w'; $widthDescriptor = $candidateWidth . 'w'; }