I am trying to get my grid images cropped without any framing. I seem to have two issues with this:
<image id="product_page_more_views" type="thumbnail">
<width>100</width>
<height>100</height>
<constrain>false</constrain>
<frame>false</frame>
<transparency>false</transparency>
<background>[248,248,248]</background>
</image>
If anybody has any idea how i should get this working..
The GitHub issue tracker is intended for technical issues only. Please refer to the Community Forums or Magento Stack Exchange site for technical questions. In your case, the programming questions forum is likely the most appropriate. Feel free to reopen this issue if you think you have encountered a bug in Magento 2.
I faced the same problem and here are my 2 cents on this.
Setting an image attribute (constrain or frame) to false in XML file does not work because "false" is converted as a string by Magento\Catalog\Helper\Image::init() (https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Helper/Image.php#L179) and is passed to Magento\Catalog\Model\Product\Image::setConstrainOnly() (https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Model/Product/Image.php#L309) which casts it as a boolean.
Since, in PHP, (bool) "false" evaluates to true, setting frame to false actually activate it.
Please note that setting boolean attributes to 0 in XML does not work either because Magento\Catalog\Helper\Image::setImageProperties() uses empty PHP function to check if the value need to be set in the image model.
empty(0) evaluates to true, so the value won't be set.
I assume this must have been intentional.
Surprisingly, Magento\Catalog\Model\Product\Image\Cache::processImageData() method (which is used by the catalog:images:resize command) uses isset() to check if values need to be set.
As a result, if we set a boolean attribute to 0 in the XML, it will be read by catalog:images:resize but ignored in front and we end up with image cache issues.
@davidalger Could you re-open this ticket ?
@davidalger I've also had this issue and it is a bug. I needed to implement a fix in the core using the comments above to resolve the issue.
Please re-open the ticket or reference it to a duplicate if one exists.
This has now been reported and acknowledged here:
On Magento 2.2.2 Open Source exist this BUG until now.
If you add the attribute <frame>false</frame> to your view.xml, then should this cropping the image. But this can not working, this feature is not integrated to call the method from the image processor (Gd2 or ImageMagick).
I have made a module to enable 'crop' for the image processor. It is free.
composer require vitd/m2_fiximagemodule
If you found an issue, write an 'Issue Ticket' (you will find the repo link on the packagist site for the module).
Good Luck ;)
Most helpful comment
Please note that setting boolean attributes to 0 in XML does not work either because
Magento\Catalog\Helper\Image::setImageProperties()uses empty PHP function to check if the value need to be set in the image model.empty(0)evaluates totrue, so the value won't be set.I assume this must have been intentional.
Surprisingly,
Magento\Catalog\Model\Product\Image\Cache::processImageData()method (which is used by the catalog:images:resize command) uses isset() to check if values need to be set.As a result, if we set a boolean attribute to 0 in the XML, it will be read by catalog:images:resize but ignored in front and we end up with image cache issues.
@davidalger Could you re-open this ticket ?