Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brendanmckeown opened this issue May 23, 2016 · 8 comments
Closed
Assignees
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@brendanmckeown
Copy link

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];
    }
@leoquijano
Copy link

leoquijano commented May 24, 2016

I can confirm the issue:

Setting the value to "false" in view.xml will make it true:
(bool) "false" = true

Setting the value to "0" in view.xml will make it empty:
empty("0") = true

Thanks @brendanmckeown for the workaround, it does work.

@zanilee
Copy link
Contributor

zanilee commented May 24, 2016

Hi, @brendanmckeown!

Thank you for reporting this issue. Internal ticket MAGETWO-53411

@Yonn-Trimoreau
Copy link

+1

@palamar palamar added bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Jun 22, 2016
@vkorotun vkorotun removed the CS label Aug 4, 2016
@markdavies
Copy link

This is still an issue months later, any update?

@PascalBrouwers
Copy link
Contributor

@rgoncharuk Can you merge the pull request #7262 ?
It passed all checks, etc.

@ishakhsuvarov
Copy link
Contributor

@brendanmckeown @markdavies @PascalBrouwers
PR #7262 is now merged into the develop branch. Issue should be fixed. Closing.

@stianmartinsen
Copy link

@brendanmckeown Before PR #7262 is live, do you have any idea why your fix works smoothly in dev mode, but not in production mode?

@tigerx7
Copy link

tigerx7 commented May 8, 2017

@stianmartinsen I may have found the reason why... by correcting the boolean value for keepFrame, it exposed a bug in https://github.com/magento/magento2/blob/2.1/app/code/Magento/Catalog/Model/Product/Image/ParamsBuilder.php in which build() checks the frame parameter with the empty function $frame = !empty($imageArguments['frame']) which will evaluate that if statement as false since empty will return true on a false value. Since the if statement is evaluated as false, ParamsBuilder::build() uses the classes default value for keepFrame which is true.

$frame = !empty($imageArguments['frame'])
    ? $imageArguments['frame']
    : $this->keepFrame;

So although the images are being created correctly now, since ParamsBuilder is returning the incorrect parameters that are used for the MD5 cache directory hash, the url path returned to the frontend gallery is pointing to the wrong cache directory.

This one was a frustrating bug to hunt down since it was giving the impression that the original problem fixed by PR #7262 was still occurring. I have no idea why empty() is being used to check the existence of the frame argument in build(). Perhaps isset() was meant to be used? I really wish Magento had a much more improved QA; too many critical bugs are still making their way into releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests