문제

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).

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top