Resize product images in Magento2

To resize product images in Magento2,  you just have to add a etc/view.xml into your own theme (f.e. app/design/frontend/Sheldon/Happytheme/etc/view.xml) ans add something like that:

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<view xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/view.xsd">
    <media>
        <images module="Magento_Catalog">
            <image id="product_image" type="image">
                <width>800</width>
                <height>800</height>
            </image>
            <image id="product_small_image" type="small_image">
                <width>500</width>
                <height>500</height>
            </image>
            <image id="product_thumbnail_image" type="thumbnail">
                <width>300</width>
                <height>300</height>
            </image>
            <image id="swatch_image" type="swatch_image">
                <width>75</width>
                <height>75</height>
            </image>
        </images>
    </media>
</view>

As you can see, you can adapt the image dimensions for each image type available. That works also for self installed image types. The values for width and height are pixel values. That’s all about resize product images in Magento2. We don’t need a single line of PHP in version 2! That’s pretty cool, isn’t it? 😉

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.