Skip to content

Conversation

@bhoopatparmar
Copy link

@bhoopatparmar bhoopatparmar commented Dec 29, 2022

Preconditions

  1. PHP 8.1
  2. Magento 2.4.5-p1

Description (*)

Gif image loading issue on the product page,
imagecolorsforindex(): Argument #2 ($color) is out of range in /var/www/lib/Varien/Image/Adapter/Gd2.

Steps to Reproduce (*)

  1. Set the image below as a product image and save it.
    test

  2. Reindex the indexer and clear the cache

  3. Open that particular product in frontend.

Expected Result

Product page must load properly

Actual Result

ValueError: imagecolorsforindex(): Argument #2 ($color) is out of range in /var/www/public_html/vendor/magento/framework/Image/Adapter/Gd2.php:347
Stack trace:
#0 /var/www/public_html/vendor/magento/framework/Image/Adapter/Gd2.php(347): imagecolorsforindex(Object(GdImage), 255)
#1 /var/www/public_html/vendor/magento/framework/Image/Adapter/Gd2.php(288): Magento\Framework\Image\Adapter\Gd2->applyTransparency(Object(GdImage), 255)
#2 /var/www/public_html/vendor/magento/framework/Image/Adapter/Gd2.php(432): Magento\Framework\Image\Adapter\Gd2->fillBackgroundColor(Object(GdImage))
#3 /var/www/public_html/generated/code/Magento/Framework/Image/Adapter/Gd2/Interceptor.php(59): Magento\Framework\Image\Adapter\Gd2->resize(240, 300)
#4 /var/www/public_html/vendor/magento/framework/Image.php(115): Magento\Framework\Image\Adapter\Gd2\Interceptor->resize(240, 300)

Solution

When the product page loads some relevant gif image, it tries to resize it via Gd2 library of php with specific functionalities. It checks the transparency of the image and creates a new transparent background image according to the particular image if needed. In that, the color transparency index is returned by imagecolortransparent($imageResource) and it can be larger than the pallet size of the image in some cases.

The index of the transparency color is a property of the image. So it's possible that an image created with this index could be set outside the pallet size.

The Gd2.php file located is at : vendor/magento/framework/Image/Adapter
imagecolortransparent($imageResource) should return -1 when the color transparency is greater than the pallet size of the image, which means that the image doesn't have any transparency
And when it calls applyTransparency() function for gif image at line 341 with $transparentIndex got by imagecolortransparent($imageResource), It checks the condition at line 346 where it checks
if ($transparentIndex >= 0 && $transparentIndex <= imagecolorstotal($this->_imageHandler)) .

But the transparent color index returned by imagecolortransparent() must be less than the pallet size of the image for an appropriate result and it shouldn't be equal to or greater than the pallet size.
Therefore we need to change condition as :
if ($transparentIndex >= 0 && $transparentIndex < imagecolorstotal($this->_imageHandler))
And if the condition satisfies then only it can look to get the new identifier for transparent color.

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Dec 29, 2022

Hi @bhoopatparmar. Thank you for your contribution
Here are some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here

ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.

For more details, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@bhoopatparmar bhoopatparmar changed the title gif image transparency issue gif image throws error on frontend Product page Dec 30, 2022
@bhoopatparmar bhoopatparmar changed the title gif image throws error on frontend Product page Gif image throws error on frontend product page Dec 30, 2022
@mortenbirkelund
Copy link

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@engcom-Hotel engcom-Hotel added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Jan 3, 2023
@sinhaparul sinhaparul added the Project: Community Picked PRs upvoted by the community label Mar 26, 2023
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@bhoopatparmar bhoopatparmar closed this by deleting the head repository Mar 28, 2023
@bhoopatparmar bhoopatparmar reopened this Mar 28, 2023
@m2-assistant
Copy link

m2-assistant bot commented Mar 28, 2023

Hi @bhoopatparmar. Thank you for your contribution!
Here are some useful tips on how you can test your changes using Magento test environment.

Add the comment under your pull request to deploy test or vanilla Magento instance:
  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to take care of the failed tests

@jupiterhs
Copy link

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@bhoopatparmar
Copy link
Author

@sinhaparul I've deleted the previous fork repository by mistake, which closed this pull request. So, I've created a new pull request with the same details. Can you please add a label to the new PR: #37319

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Project: Community Picked PRs upvoted by the community

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants