magento2: Magento 2.4.4 Mini cart item images not showing
Preconditions and environment
- Magento 2.4.4
- PHP8.1
Steps to reproduce
- Go to Content >> Design >> Configuration >>Edit theme >>Product Image Watermarks >> Thumbnail
- Upload image with Thumbnail and set image position as “Center”
- Add Products to Cart that all products have images.
- Open Minicart.
- Run
bin/magento catalog:image:resize
and observe the error in the terminal.
Expected result
All item images in Minicart get the images
Actual result
All item images are replaced by the default Product placeholder image
Additional information
I have debugged in this file vendor/magento/module-catalog/Helper/Image.php
public function getUrl()
{
try {
switch ($this->mediaConfig->getMediaUrlFormat()) {
case CatalogMediaConfig::IMAGE_OPTIMIZATION_PARAMETERS:
$this->initBaseFile();
break;
case CatalogMediaConfig::HASH:
$this->applyScheduledActions();
break;
default:
throw new LocalizedException(__("The specified Catalog media URL format is not supported."));
}
return $this->_getModel()->getUrl();
} catch (\Exception $e) {
\Magento\Framework\App\ObjectManager::getInstance()->get('Psr\Log\LoggerInterface')->info($e->getMessage());
return $this->getDefaultPlaceholderUrl();
}
}
then got those errors
Deprecated Functionality: Implicit conversion from float 12.5 to int loses precision in /home/stagefish/public_html/stage.livefish.com.au/vendor/magento/framework/Image/Adapter/Gd2.php on line 963 [] []
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 2
- Comments: 24 (6 by maintainers)
Commits related to this issue
- magento/magento2#35535: Magento 2.4.4 Mini cart item images not showing - Cast resized image dimensions from floats to integers for GD and ImageMagick as imagecopy expects ints — committed to craig-bartlett/magento2 by craig-bartlett 2 years ago
- Merge pull request #1 from craig-bartlett/issue-35535-cast-floats-to-ints magento/magento2#35535: Magento 2.4.4 Mini cart item images not showing — committed to craig-bartlett/magento2 by craig-bartlett 2 years ago
Hi,
I’ve recently come across this same issue. It is indeed caused by theme images with an odd dimension and the watermark position set to centre. If using the Gd2 adapter, it uses the following to calculate the position:
If the image size has an odd dimension, this results in a float. These are then passed to imagecopymergeWithAlphaFix on the next line, which passes them to imagecopy. This function expects integers and therefore gives the warning that the OP reported. I think the same is true for the ImageMagick adapter as it handles it in the same way.
For what it’s worth - when debugging this I didn’t see any warnings at all in the system or debug log, only managing to get the output the OP saw by wrapping the call to createWatermarkBasedOnPosition in a try/catch. The only sign I had that something was wrong was several missing folders in media/catalog/product/cache which relate to the sizes that were being silently skipped. Generating the images from the command line also gave no errors/warnings. It’s worth noting that I couldn’t find anything in the documentation regarding the use of odd dimensions with image sizes.
I patched this for our instances (2.4.4) by explicitly casting the resulting positions to integers. It works for us but your results may vary.
And for ImageMagick:
Its not only cart and checkout, its on every page where an image from a product exists.
When passing the positionX and positionY to this function, its always an int. But it can become a float when caculations are made.
That happens not only on line https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L541
But also on:
https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L542 https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L580 https://github.com/magento/magento2/blob/2.4-develop/lib/internal/Magento/Framework/Image/Adapter/Gd2.php#L594
Awesome, thanks!