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?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityThere 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
Create a custom cli tool by using this - https://devdocs.magento.com/guides/v2.4/extension-dev-guide/cli-cmds/cli-howto.html
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);
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.