I have the following situation:

I have set my images size for single page in view.xml let say 2000x2000


The image now is ok, and is 2000x2000.

My problem:

If a will upload a image with 1200x800, or another values the images look stretch or small and looks really wierd.

Is there a solution to avoid the resize? or can be set a "auto" value in view xml?

What i want, is to upload a picutres, and afert this I want the original size to be shown on the page.

Is this possible?

2 Answers 2


I am not sure if this will help because I have a different version, but if you go into you

System > Configuration > Theme settings > Category view/Images 

Make sure you have yes for "Keep Image Aspect Ratio" - "Image aspect ratio size" to square rectangle and set the image width (recommended 270) and height (recommended 365), this should help without you having to resize any images.


I found a solution. For single page image I found the function that load the pictures and I modified this function to load the pictures with the real size, without having to resize anything.

This is my function:

namespace namespace\Resize\Block\Catalog\Product\View;

class Gallery extends \Magento\Catalog\Block\Product\View\Gallery

   public function getGalleryImagesJson()
        $product = $this->getProduct();
        $imagesItems = [];
        foreach ($this->getGalleryImages() as $image) {
            //change the path of the photo for the single product 
            $imagesItems[] = [
                'thumb' => $this->getBaseUrl().'pub/media/catalog/product/'.$image['file'],
                'img' => $this->getBaseUrl().'pub/media/catalog/product/'.$image['file'],
                'full' => $this->getBaseUrl().'pub/media/catalog/product/'.$image['file'],
                'caption' => $image->getLabel(),
                'position' => $image->getPosition(),
                'isMain' => $this->isMainImage($image),
        if (empty($imagesItems)) {
            $imagesItems[] = [
                'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl('thumbnail'),
                'img' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
                'full' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
                'caption' => '',
                'position' => '0',
                'isMain' => true,
        return json_encode($imagesItems);


and my di.xml

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">       
    <type name="Magento\Catalog\Block\Product\View\Gallery">
        <plugin name="plugin_block_catalog_product_view_gallery"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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