From c9786df7fa52ae92a07da17c56278ac6a910de4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mateos?= Date: Tue, 31 Oct 2017 02:38:05 +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 977e76509afd2..74641aa1bd836 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 d133c1dea71ea7e499fabf271497d2d9bed8ef0b Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Fri, 3 Nov 2017 15:33:52 +0200 Subject: [PATCH 2/2] magento/magento2#11890: Save background color correctly in images. - 2.1 backport --- 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 74641aa1bd836..2b521cc732a2a 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 23b17ed8b5304..c952af85ea6e1 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')); } /**