Magento2: php bin/magento catalog:images:resize does not process hidden images.

Created on 15 May 2020  ·  14Comments  ·  Source: magento/magento2

Preconditions (*)

  1. Magento 2.4-develop

Steps to reproduce (*)

  1. Create a Product
  2. Assign Image 1 to product and set to be visible on product page
  3. Assign Image 2 to product and set to be hidden on product page
  4. Save the product

Expected result (*)

  1. View the product page, only Image 1 should be visible
  2. pub/media/catalog/cache folder should contain resized Image 1's
  3. pub/media/catalog/cache folder should contain resized Image 2's
  4. Clear image cache
  5. Run php bin/magento catalog:images:resize
  6. pub/media/catalog/cache folder should contain resized Image 1's
  7. pub/media/catalog/cache folder should contain resized Image 2's

Actual result (*)

  1. Only Image 1 is visible on product page ✅
  2. Image 1 is present in cache in resized states ✅
  3. Image 2 is present in cache in resized states ✅
  4. Cache is cleared ✅
  5. Image resize command processes 1 image, not 2 ❌
  6. pub/media/catalog/cache folder should contain resized Image 1's ✅
  7. pub/media/catalog/cache folder does not contain resized Image 2's ❌

Images that are hidden from the product page are not processed by the image resize command. They should be. Just because they are hidden from the product page, doesn't mean they won't be used elsewhere.

Magento is written so that hiding the product image, actually sets it to disabled.

IMHO setting a product image to disabled, and setting it to be hidden on product page are two very different settings, but magento currently treats them as the same.

The confusion stems from the hidden setting being stored in the database as the field disabled. A hidden image is NOT a disabled image, and should still be processed, just not displayed on the product page, otherwise, what is the point of the hidden setting?

ready for confirmation Reported on 2.4.0

Most helpful comment

Perhaps there should be 2 settings, "hidden" and "disabled"

All 14 comments

Hi @gwharton. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, please, review the Magento Contributor Assistant documentation.

@gwharton do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • [ ] yes
  • [ ] no

I have also mentioned this issue as https://github.com/magento/magento2/issues/28182

Note, this behaviour was introduced in commit 048a2ee6b6f7215ea3168773730bff2f0ec2f01f

Hi @engcom-Delta. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch

    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Add label Issue: Confirmed once verification is complete.

  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

Looks like the change was made on purpose as an optimisation.

HI @gwharton could you provide case where we can reuse same hidden image? Image uploaded for product cannot be used by media gallery and same image uploaded for another product has new name in database (name + increment index)
image

@engcom-Delta I have a separate custom written module that uploads product data to Google Shopping and Google My Business. I need to use different product images for Google feeds than on my front end, so when I create a product I upload two images, one for front end, and one hidden one for Google. My module then picks up this hidden image url and uses that on the google feeds.

The setting in Magento is named "Hide from Product Page", so seems like the perfect setting for me. And infact, it is the way that Magento works when you initially upload an image for a product. Setting it to hidden on the catalog page, DOES generate the cached images for it, regardless of its hidden state. The cached images only dissapear when you clear image cache and then regenerate using catalog:images:resize. There is an inconsistency there.

If this isn't going to be fixed for catalog:images:resize, then Magento should be changed so that it does not generate cached images for new hidden images when they are uploaded to make it consistent, i.e cached images are not generated for hidden images, and the setting should also be changed on the frontend to "Disabled" instead of "Hidden from product page" to reflect the actual setting that is applied.

In my module I call

$this->imageBuilder->setProduct($product)
                    ->setImageId('product_page_main_image_gmb')
                    ->setAttributes([])
                    ->create()
                    ->getImageUrl();

where product_page_main_image_gmb is a custom image type I have defined in my view.xml.

The url returned by this call returns a 404, when the image is "Hidden from product page" as the cached images were not processed by catalog:images:resize after an images cache clear.

Perhaps there should be 2 settings, "hidden" and "disabled"

Due to this cart and wishlist page shows placeholder images if small/thumbnail image is set to Hide from Product page.
Any update on this?

You can manually apply a patch as a workaround.

composer require vaimo/composer-patches

patches/composer/imageresizeall.diff

--- Service/ImageResize.orig.php    2020-07-17 14:15:47.350000000 +0100
+++ Service/ImageResize.php 2020-07-17 14:25:30.870000000 +0100
@@ -180,12 +180,12 @@
      */
     public function resizeFromThemes(array $themes = null): Generator
     {
-        $count = $this->productImage->getCountUsedProductImages();
+        $count = $this->productImage->getCountAllProductImages();
         if (!$count) {
             throw new NotFoundException(__('Cannot resize images - product images not found'));
         }

-        $productImages = $this->productImage->getUsedProductImages();
+        $productImages = $this->productImage->getAllProductImages();
         $viewImages = $this->getViewImages($themes ?? $this->getThemesInUse());

         foreach ($productImages as $image) {

composer.json

    "extra": {
        "magento-force": "override",
        "composer-exit-on-patch-failure": true,
        "patches": {
            "magento/module-media-storage": {
                "https://github.com/magento/magento2/issues/28239": "patches/composer/imageresizeall.diff"
            }
        }
    }

composer install

Works on 2.3.5-p1

Perhaps a compromise would be a command line argument --process-hidden-images with the default to not process hidden images??

The wording "Hide from Product Page" implies the setting will only hide the image from the product page, but allowing the image to be used on the category listing page, wish list, compare, basket, any other use that is not product page... The original behaviour of only suppressing display of the image in the product page gallery is in line with the wording.

The optimisation of not generating images when "Hide from Product Page" is checked differs from the original intended purpose, which is clearly to stop supporting product images from displaying in the product page image gallery.

Many thanks to @gwharton for your patch, this works perfectly and allows the setting "Hide from Product Page" to be used as originally conceived.

The catalog:images:resize routine seems to have been butchered a bit lately, but the way I see it, there are two recent changes that would have been better suited to command line arguments to make them optional, than making it work the same for everyone.

--skip-hidden-images = Do not process images marked as hidden from product page
--skip-if-exists = Do not process an image, if it already exists. (Since https://github.com/magento/magento2/pull/26801 If you change the image, but keep the filename the same, there is no way of regenerating that image, apart from clearing entire image cache)

Lets hope that because this went to dev in progress a few weeks ago, that someone from core are on it.

Was this page helpful?
0 / 5 - 0 ratings