2

I have a custom block, which extends from \Magento\Catalog\Block\Product\View\AbstractView. Within this block I would like to retrieve the base image. I've tried in this way

$this->getImage($this->getProduct(), 'product_page_image_small');

but what I get is the thumbnail instead of the base image. Should I extend from some other class?

2 Answers 2

2

If you change your argument to 'product_page_main_image' it should give you main image.

$this->getImage($this->getProduct(), 'product_page_main_image');
3
  • good, it works! How can I get the image url without resizing?
    – giani.sim
    Commented Mar 1, 2017 at 11:06
  • To understand these sizes have a look at view.xml file which defines all of these image sizes. It should be located under your custom theme/etc if not then you can copy it from luma/etc (theme). To get the Image url from your block you can use something like: $block->getUrl('pub/media/catalog').'product'.$_product->getImage();
    – Devtype
    Commented Mar 1, 2017 at 11:33
  • Yes, I knew it. I was wondering what is the best way to get the original file URL.
    – giani.sim
    Commented Mar 1, 2017 at 11:34
1

You have to change your argument in your phtml file,

1. product_page_image_medium
2. product_page_main_image

Above both argument gives you main image of product and using above argument your image should display like,

<width>700</width>
<height>560</height>

e.g.

$this->getImage($this->getProduct(), 'product_page_image_medium');

or

$this->getImage($this->getProduct(), 'product_page_main_image');

When you had used product_page_image_small its return only 88x110 size image.

You can more check size dimension from vendor/magento/theme-frontend-luma/etc/view.xml file for size dimension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.