0

Please check the below code

app\code\Vendor\Category\etc\di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">

    <type name="Magento\Catalog\Model\Product\Image">
        <plugin name="ImageWhitespace" type="Vendor\Category\Model\Product\Image" sortOrder="1" />
    </type>
</config>

app\code\Vendor\Category\Model\Product\Image.php

<?php

namespace Vendor\Category\Model\Product;

    class Image
    {
        public function beforeSetKeepFrame($image, $keep)
        {
            if (is_string($keep)) {
                $keep = (strtolower($keep) === 'true') ? 1 : 0;
            }
            return [$keep];
        }
}
    ?>

app\design\frontend\vendor\customtheme\etc\view.xml

 <?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="category_page_list" type="small_image">
                <width>237</width>
                <height>341</height>
                <frame>false</frame>
            </image>
             <image id="product_page_image_medium" type="image">
                    <width>295</width>
                    <height>400</height>
                    <frame>false</frame>
                </image>

                <image id="upsell_products_list" type="small_image">
                    <width>237</width>
                    <height>341</height>
                    <frame>false</frame>
                </image>

                 </images>
        </media>
    </view>
1

Product images are cached while saving the product from admin panel. However, sometimes you may need to re-create the product images cache after you import products, if images were resized manually in the cache, or if the cache was manually cleared by mistake.

Command :

php <magento install dir>/bin/magento catalog:images:resize

This command takes no arguments or options,The message Product images resized successfully. displays to confirm the command succeeded.

  • ,i did it but still whitespace are coming – Hitesh Balpande Jan 18 at 7:09
  • in my case if in catagory list page size image is adding then it is fine here with no whitespace but for details page and upsell products images are coming with whitespace – Hitesh Balpande Jan 18 at 7:12
  • 1
    white space coming,that mean images resize resolution is not correct, calculate the image resolution based on the original image size and then white space won't come – Rahul Singh Jan 18 at 7:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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