Skip to content

Setting image keep frame to false in theme's view.xml does not work #4622

@brendanmckeown

Description

@brendanmckeown

Steps to reproduce

  1. In the current theme's view.xml file, add <frame>false</frame> to a specific image type as instructed in the docs: http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/themes/theme-images.html . This image should also have a width and height setting and aspect_ratio set to true. For example:
            <image id="category_page_grid" type="small_image">
                <width>460</width>
                <height>460</height>
                <aspect_ratio>true</aspect_ratio>
                <frame>false</frame>
            </image>
  1. Clear image cache, refresh a page with this specific image type.

Expected result

  1. Image should keep its aspect ratio, not have any added white frame, and size should be within the configured width and height.

screen shot 2016-05-22 at 9 41 50 pm

## Actual result 1. Image is forced to width and height with white frame, and does not keep original aspect ratio.

screen shot 2016-05-22 at 9 42 15 pm

Cause:
The value from view.xml is passed to the method \Magento\Catalog\Model\Product\Image::setKeepFrame – which casts the string "false" to the boolean true. Therefore, it is not possible to set keep_frame to false from within the view.xml.

    /**
     * @param bool $keep
     * @return $this
     */
    public function setKeepFrame($keep)
    {
        $this->_keepFrame = (bool)$keep;
        return $this;
    }

After creating a plugin to convert the string value to an integer (which properly casts to a boolean), the image frame is not added.

    public function beforeSetKeepFrame($image, $keep)
    {
        if (is_string($keep)) {
            $keep = (strtolower($keep) === 'true') ? 1 : 0;
        }
        return [$keep];
    }

Metadata

Metadata

Assignees

Labels

Issue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentbug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions