From 9c80e90e5223a37281ba473f3d879a75ecc1336e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl?= Date: Tue, 31 Oct 2017 02:29:38 +0100 Subject: [PATCH 1/2] Save color correctly in background image --- app/code/Magento/Catalog/Model/ImageExtractor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ImageExtractor.php b/app/code/Magento/Catalog/Model/ImageExtractor.php index c12db4dba49d7..63e1801195add 100644 --- a/app/code/Magento/Catalog/Model/ImageExtractor.php +++ b/app/code/Magento/Catalog/Model/ImageExtractor.php @@ -5,10 +5,11 @@ */ namespace Magento\Catalog\Model; -use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter; use Magento\Catalog\Helper\Image; +use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter; +use Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface; -class ImageExtractor implements \Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface +class ImageExtractor implements TypeDataExtractorInterface { /** * Extract configuration data of images from the DOM structure @@ -55,6 +56,7 @@ private function processImageBackground($backgroundString) $backgroundArray = []; if (preg_match($pattern, $backgroundString, $backgroundArray)) { array_shift($backgroundArray); + $backgroundArray = array_map('intval', $backgroundArray); } return $backgroundArray; } From 761bd2498ce76d219c39aa63689ea571e0bdcbea Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Fri, 3 Nov 2017 15:39:41 +0200 Subject: [PATCH 2/2] magento/magento2#11888: Save background color correctly in images. --- app/code/Magento/Catalog/Model/ImageExtractor.php | 5 ++++- .../Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ImageExtractor.php b/app/code/Magento/Catalog/Model/ImageExtractor.php index 63e1801195add..7888d8de1c2ff 100644 --- a/app/code/Magento/Catalog/Model/ImageExtractor.php +++ b/app/code/Magento/Catalog/Model/ImageExtractor.php @@ -31,8 +31,11 @@ public function process(\DOMElement $mediaNode, $mediaParentTag) if ($attribute->nodeType != XML_ELEMENT_NODE) { continue; } - if ($attribute->tagName == 'background') { + $attributeTagName = $attribute->tagName; + if ($attributeTagName === 'background') { $nodeValue = $this->processImageBackground($attribute->nodeValue); + } elseif ($attributeTagName === 'width' || $attributeTagName === 'height') { + $nodeValue = intval($attribute->nodeValue); } else { $nodeValue = $attribute->nodeValue; } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php index 05ed780fc1e3d..3b0262aa99e4f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ImageExtractorTest.php @@ -23,7 +23,7 @@ protected function setUp() public function testProcess() { $expectedArray = include(__DIR__ . '/_files/converted_view.php'); - $this->assertEquals($expectedArray, $this->model->process($this->getDomElement(), 'media')); + $this->assertSame($expectedArray, $this->model->process($this->getDomElement(), 'media')); } /**