Magento2 – How to Stop Generating All Image Types in Cache on Page Visit

cachegallery-imagemagento2media-imagesproduct-images

I'm using Magento 2.2.5 and when we visit listing or product page Magento creates the various sizes of images in pub/media/catalog/product/cache/ directory which I don't need except some.

I have checked file vendor/magento/framework/Config/etc/view.xsd but, nothing found related to stop/disable image generation.

As this creates lots of images and acquires disk spaces.

How to disable a particular type of image generation or anyone know the flow of image generation?

Best Answer

After debugging, we found that Magento internally calls various types of images in different files and they are generated.

We have implemented a workaround in the following way.

override all the image type and use the image dimensions which near the dimension we use in

app/design/frontend/Vendor/theme_01/etc/view.xml

and override the file which returns the image-file path hash according to misc-parameters like image's height, width, aspect ratio. We made it according to our requirement.

Magento\Catalog\Model\View\Asset\Image.php

As in our case, we need just a simple image and all other misc params are remain the same in all cases, we made return directory path like '100x90' as a directory name.

thus we get the 100x90 image in the pub/media/catalog/product/cache/100x90 directory

Related Topic