3

I have the following situation:

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

 <width>2000</width>
 <height>2000</height>

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?

asked Aug 16, 2017 at 11:45

2 Answers 2

0

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.

diazwatson
2,4782 gold badges28 silver badges39 bronze badges
answered Aug 16, 2017 at 13:29
0

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"
 type="namespace\Resize\Block\Catalog\Product\View\Gallery"
 sortOrder="10"
 disabled="false"/>
 </type>
</config>
Vivek Kumar
5,7932 gold badges26 silver badges55 bronze badges
answered Jan 10, 2018 at 9:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.