Skip to content

Conversation

@craig-bartlett
Copy link
Contributor

  • Cast resized image dimensions from floats to integers for GD and ImageMagick as imagecopy expects ints

Description (*)

If images have odd dimensions then when they are resized in the image adapters for GD and ImageMagick the resulting dimensions are stored as floats:

$positionX = $this->_imageSrcWidth / 2 - imagesx($watermark) / 2;

These are later passed to PHP's imagecopy function which expects integers and so throws warnings. This results in the offending image size being missed when generating catalog images. Simply casting the results of the resizing lines to ints fixes this.

$positionX = (int) ($this->_imageSrcWidth / 2 - imagesx($watermark) / 2);

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes Magento 2.4.4 Mini cart item images not showing #35535

Manual testing scenarios (*)

  1. As mentioned in the issue thread by @benyatesvortex, this can be tested by running the image resize command manually (bin/magento catalog:image:resize). If either the width or height are odd (and the watermark is even), the result will be a float causing imagecopy() to throw a warning and the image to be skipped.

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)

- Cast resized image dimensions from floats to integers for GD and ImageMagick as imagecopy expects ints
…ints

magento#35535: Magento 2.4.4 Mini cart item images not showing
@m2-assistant
Copy link

m2-assistant bot commented Oct 26, 2022

Hi @craig-bartlett. 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

@ihor-sviziev ihor-sviziev added the Priority: P2 A defect with this priority could have functionality issues which are not to expectations. label Oct 26, 2022
@ihor-sviziev
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.

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a comment

Choose a reason for hiding this comment

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

Would be nice to cover this with an automated test in case manual QA passes.

@engcom-Lima
Copy link
Contributor

Hi @craig-bartlett ,

Thanks for your contribution and collaboration.

I have tried to reproduce the issue but issue is not reproducible to me.
I have followed below steps to reproduce the issue:

  1. Created a product with image having dimensions in odd and with watermark.
  2. Add Products to Cart
  3. Ran bin/magento catalog:image:resize
  4. Open Minicart

But I am image is displaying in the mini cart. Below is the screenshot for your reference:
image

Please provide us more information in order to reproduce the issue.

Thanks

@craig-bartlett
Copy link
Contributor Author

@engcom-Lima Hi, was the instance running PHP 8.1? The theme's image size width or height should be odd and the watermark position must be set to centred. I forgot to mention that last part - it must be set to centred to reach the code in question.

@engcom-Lima
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Lima. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-Lima
Copy link
Contributor

Hi @craig-bartlett ,

Thanks for your contribution and collaboration.

I have tried to reproduce the issue but issue is not reproducible to me. I am testing it on 2.4-develop with PHP 8.1 . Also checked in Magento with and without sample data.
Below are the images which I have used as sample for testing:


test2


w2 (1)


test2 (1)


Below is the screenshot for your reference as images in mini cart is displaying properly:


Screenshot 2022-10-31 at 1 43 27 PM

__________________________________________________________________________________________________

As mentioned I have used image size in odd and I ran indexer as well as bin/magento catalog:image:resize command but no luck. Kindly provide us sample image which you have used also provide more information inorder to reproduce the issue. Kindly test it in latest 2.4-develop and let us know if you are facing any issue.

Thanks

@craig-bartlett
Copy link
Contributor Author

Hi @engcom-Lima

Was the image size in the theme set to an odd dimension? It's not the physical image size but the theme's image size set in the theme file (etc/view.xml) for the particular image you are using (in this case mini_cart_product_thumbnail).

@engcom-Lima
Copy link
Contributor

@magento give me 2.4-develop instance

@magento-deployment-service
Copy link

Hi @engcom-Lima. Thank you for your request. I'm working on Magento instance for you.

@magento-deployment-service
Copy link

@engcom-Lima
Copy link
Contributor

engcom-Lima commented Oct 31, 2022

✔️ QA Passed

Preconditions:

  • Install fresh Magento 2.4-develop

Manual testing scenario:

  1. Go to Content >> Design >> Configuration >>Edit theme >>Product Image Watermarks >> Thumbnail
  2. Upload image with Thumbnail and set image position as "Center"
  3. Add Products to Cart that all products have images.
  4. Open Minicart.
  5. Run bin/magento catalog:image:resize and observe the error in the terminal.

Before: ✖️ Mini cart image disappeared.

Minicart:
Screenshot 2022-10-31 at 4 17 27 PM

Terminal:
Screenshot 2022-10-31 at 4 18 24 PM

After: ✔️ Now image is displaying in the mini cart.

Minicart:
Screenshot 2022-10-31 at 4 23 25 PM

Terminal:
Screenshot 2022-10-31 at 4 35 26 PM

Additionally tested:

  1. Added configurable and simple product to the cart from guest / customer.
  2. Placed an order from guest/ customer.

Added to regression scope.

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. Progress: accept QA: Added to Regression Scope Scenario was analysed and added to Regression Testing Scope

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Magento 2.4.4 Mini cart item images not showing

5 participants