1

The below command will re-size all images based on new specified dimensions:

php bin/magento catalog:images:resize

Is there a variable to add to run for a certain image type only? For example, swatch or thumb only?

2 Answers 2

2

There is no straight forward answer to pass diff image types.

Because the way of doing resizing involves all the Themes, Stores, and Image types around 40-50 types (which are available in every theme file Namespace/Themename/etc/view.xml).

This runs for all the product images which will obviously consume more time.

One thing is to remove the unnecessary image tag from the etc/view.xml showing under <images module="Magento_Catalog"> from your respective theme files.

comment out below or other tag which does not active:

<image id="bundled_product_customization_page" type="thumbnail">
            <width>140</width>
            <height>140</height>
        </image>

Another way, there is one private method getViewImages is available in the file

Here, you can add a condition like in the foreach loop by overriding the preference to this file. This will surely reduce a lot of time.

//Only type = image will be proceed
if ($imageData['type'] !== 'image') {
    continue;
}

You can create custom cli tool based on ImageResizeCommand the acting below: https://github.com/magento/magento2/blob/2.3/app/code/Magento/MediaStorage/Console/Command/ImagesResizeCommand.php#L81

  1. Create a custom cli tool by using this - https://devdocs.magento.com/guides/v2.4/extension-dev-guide/cli-cmds/cli-howto.html

  2. In file Console\WhateverNameCommand.php, you can take the whole ImagesResizeCommand.php class from Magento.

    $themeId = 1; //Get this from theme table $themeObject = $this->themeModelFactory->create()->load($themeId); $this->resize->resizeFromThemes($themeObject);

1

This is related to v2.3.x

I would assume not, looking at the code of Magento 2 ImagesResizeCommand.

You might need to create a new custom module to override function execute() and possibly target information inside $resizeInfo[] array, for example filename.

(For example, you might create new custom arguments to the constructor in your module and target those conditions)

NOTE: I see the upcoming v2.4x version will be vastly different - functions like executeSync and executeASync will handle the execute() independently.

2
  • Thanks. Thought the answer would be no. Nothing online about at all at the moment. Issue occurs when you run the command on a huge catalogue, and it can take days to complete. Timing out in the middle regularly. Which then goes back to the start of the query on next run......
    – MagentoMac
    Jun 2, 2020 at 11:35
  • Yeah days for import/migration etc... and then when there are errors you need to start from the beginning can be extremely frustrating. I guess you should try your custom module (if you want to try and implement it) on a local installation with a few products / images only. Please mark answer if it was helpful. Jun 2, 2020 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.