0

I'm having trouble getting the product images to behave on product view pages.

This screen shot is from the product view page. You can see the white bars down the side. All these images seem to be resized to 700x700 with white backgrounds (which are part of the image not css). Full screen and thumbnails are fine.

Badly resized image

The config for these images is defined in view.xml under the tag The data for the gallery comes from getGalleryImagesJson() and the urls defined in getGalleryImages() in Gallery.php. The image is loaded with keepFrame(false) and with the size from product_page_image_large which is set to 780x1000 in view.xml. My understanding is this shouldn't add bars. I've also added <frame>false</frame> but no help.

I'm using magento 2.1.6 and have tried running magento catalog:images:resize and flushing caches etc.

Edit:
I've noticed I was looking at out of date magento code and keepFrame, constrainOnly and keepAspectRatio aren't forced any more. Also product_page_image_medium should now be product_page_image_medium_no_frame.

From the docs I've added this to the appropriate _no_frame blocks in view.xml:

<frame>false</frame>
<constrain>true</constrain>
<aspect_ratio>true</aspect_ratio>

As I understand it this should give me images without borders with fixed aspect ratios a maximum of the defined size. NOW I've got correct aspect ratio images at the right size but with white bars on all edges. I should be missing those bars (unless I just don't understand).

  • Keep frame keeps the frame. Otherwise it would be cropped to fit the dimensions. Your defined aspect ratio is not the same as the uploaded image. You should crop/resize your images uploaded to fit the .78 aspect ratio you're defining in the code. – philwinkle Apr 19 '17 at 21:11
  • Correct me if I'm wrong but keepFrame(false) should not keep the frame. It shouldn't matter that the aspect ratios don't match, it should just use those as max bounds and scale as far as it can. As it happens I was looking at out of date source code. The block in view.xml has changed from product_page_image_medium to product_page_image_medium_no_frame and constainOnly, keepFrame and keepAspectRatio aren't forced anrymore. The default is loaded from Magento/Blank and defines the troublesome images as 700x700. Unfortunately I've now got white bars top and bottom as well as on the sides. – Chris Lingwood Apr 19 '17 at 21:50
-1

It appears I hit a bug for which there is a PR https://github.com/magento/magento2/pull/7262 All of the settings bar height and width in view.xml are ignored. It is caused by some code expecting a bool but getting a string. The fix has not made it's way into a release yet (currently 2.1.6) even though there has been one since the fix went in.

In short there a few changes to make to app/code/Magento/Catalog/Model/Product/Image.php in the style of:

-        $this->_keepAspectRatio = (bool)$keep;
+        $this->_keepAspectRatio = $keep && $keep !== 'false';

There is one for each boolean parameter detailed in the PR.

Be aware you should change the size of the image when changing these settings or it won't actually update the images when asked.

| improve this answer | |

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.