Hello Magento Friends,

With this Magento 2 tutorial, I will provide the solution for Resizing Specific Product Image using Command Line in Magento 2.

Product images attract the user’s attention. If they are not displayed properly, it will create a bad user experience. Hence, to make sure the product images fit correctly and display properly, you may need to resize them.

Magento 2 provides an image resize command which will resize all the product images at once. If you want to resize only a specific product image, the below steps will help you to accomplish it.

Steps to Resize Specific Product Image using Command Line in Magento 2:

Step 1: Create a di.xml file at the given path


Now add the code as follows

Step 2: Now, you need to create the ImagesResizeCommand.php file at the below path


Then add the following code

Step 3: After deploying this module, you need to execute this below command to resize a specific product image.

Here, test:product:resize is custom command and product_id is an argument where you need to pass your product id.


Using the above method, you can easily resize specific product images in Magento 2 via the command line. Moreover, Image Optimizer Extension for Magento 2 helps to reduce the image size without losing its quality.

Happy Coding!

Click to rate this post!
[Total: 10 Average: 2.9]