Skip to content

Commit 809f75b

Browse files
committed
Merge remote-tracking branch 'local/ACP2E-1632' into PR_6_MAR_2023
2 parents 050dd88 + 16aa0dc commit 809f75b

File tree

4 files changed

+72
-4
lines changed

4 files changed

+72
-4
lines changed

app/code/Magento/Catalog/Test/Mftf/Data/ImageData.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<data key="filename">jpg</data>
4444
<data key="file_extension">jpg</data>
4545
</entity>
46+
<entity name="GifImageWithUnusedTransparencyIndex" type="image">
47+
<data key="title" unique="suffix">GifImageWithUnusedTransparencyIndex</data>
48+
<data key="file">transparency_index.gif</data>
49+
<data key="filename">transparency_index</data>
50+
<data key="file_extension">gif</data>
51+
</entity>
4652
<entity name="LargeImage" type="image">
4753
<data key="title" unique="suffix">largeimage</data>
4854
<data key="file">large.jpg</data>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminSimpleProductGifWithUnusedTransparencyImageTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Using a GIF image with transparency color declared but not used as a product main image should not prevent the product grid from being rendered properly"/>
14+
<title value="Using a GIF image with transparency color declared but not used as a product image"/>
15+
<description value="Using a GIF image with transparency color declared but not used as a product main image should not prevent the product grid from being rendered properly"/>
16+
<severity value="CRITICAL"/>
17+
<useCaseId value="ACP2E-1632"/>
18+
<testCaseId value="AC-8028"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
22+
<before>
23+
<createData entity="_defaultCategory" stepKey="category"/>
24+
<createData entity="_defaultProduct" stepKey="firstProduct">
25+
<requiredEntity createDataKey="category"/>
26+
</createData>
27+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
28+
</before>
29+
30+
<after>
31+
<deleteData createDataKey="category" stepKey="deletePreReqCategory"/>
32+
<deleteData createDataKey="firstProduct" stepKey="deleteFirstProduct"/>
33+
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
34+
</after>
35+
36+
<!-- Navigate to the product grid and edit the product -->
37+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="goToProductIndex"/>
38+
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProductGridBySku">
39+
<argument name="product" value="$$firstProduct$$"/>
40+
</actionGroup>
41+
<actionGroup ref="OpenProductForEditByClickingRowXColumnYInProductGridActionGroup" stepKey="openProducForEditByClickingRow1Column2InProductGrid"/>
42+
43+
<!-- Set the test GIF image as a main product image and save the product -->
44+
<actionGroup ref="AddProductImageActionGroup" stepKey="addImageForProduct">
45+
<argument name="image" value="GifImageWithUnusedTransparencyIndex"/>
46+
</actionGroup>
47+
<actionGroup ref="AdminProductFormSaveActionGroup" stepKey="saveProduct"/>
48+
49+
<!-- Go back to the product grid and make sure the product is present and visible on the grid -->
50+
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="returnToProductIndex"/>
51+
<actionGroup ref="AssertProductOnAdminGridActionGroup" stepKey="assertFirstOnAdminGrid">
52+
<argument name="product" value="_defaultProduct"/>
53+
</actionGroup>
54+
55+
<actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="resetProductGridBeforeLeaving"/>
56+
</test>
57+
</tests>
Loading

lib/internal/Magento/Framework/Image/Adapter/Gd2.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,14 @@ private function applyTransparency(&$imageResourceTo, $transparentIndex): void
343343
// fill image with indexed non-alpha transparency
344344
$transparentColor = false;
345345

346-
if ($transparentIndex >= 0 && $transparentIndex <= imagecolorstotal($this->_imageHandler)) {
347-
list($red, $green, $blue) = array_values(imagecolorsforindex($this->_imageHandler, $transparentIndex));
348-
$transparentColor = imagecolorallocate($imageResourceTo, (int) $red, (int) $green, (int) $blue);
346+
if ($transparentIndex >= 0 && $transparentIndex < imagecolorstotal($this->_imageHandler)) {
347+
try {
348+
$colorsForIndex = imagecolorsforindex($this->_imageHandler, $transparentIndex);
349+
list($red, $green, $blue) = array_values($colorsForIndex);
350+
$transparentColor = imagecolorallocate($imageResourceTo, (int) $red, (int) $green, (int) $blue);
351+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch
352+
} catch (\ValueError $e) {
353+
}
349354
}
350355
if (false === $transparentColor) {
351356
throw new \InvalidArgumentException('Failed to allocate transparent color for image.');
@@ -387,7 +392,7 @@ private function _getTransparency($imageResource, $fileType, &$isAlpha = false,
387392
if (IMAGETYPE_GIF === $fileType || IMAGETYPE_PNG === $fileType) {
388393
// check for specific transparent color
389394
$transparentIndex = imagecolortransparent($imageResource);
390-
if ($transparentIndex >= 0) {
395+
if ($transparentIndex >= 0 && $transparentIndex < imagecolorstotal($imageResource)) {
391396
return $transparentIndex;
392397
} elseif (IMAGETYPE_PNG === $fileType) {
393398
// assume that truecolor PNG has transparency

0 commit comments

Comments
 (0)