简体   繁体   中英

Issue with resizing the image in product view page (media.phtml) magento

I am trying to resize image in product view page, but after the image has resized, white spaces come along in left and right both the sides (width), in resize function I gave the value 338,474, but It comes with white spaces. For that I applied function keepFrame(false) .

But after applying that, my image height remains same, but width changes to 271. What should I do? Below is my code.

<img src="<?php echo $this->helper('catalog/image')->init($product, 'image')->keepFrame(false)->resize(338,474);?>" alt='' title="<?php echo $this->htmlEscape($this->getImageLabel());?>" />

I tried keepFrame(false) both before and after resize(338,474) . Please, if any body can help me.

只需在以下函数resize传递您的高度和宽度

$_img = '<img src="'.$this->helper('catalog/image')->init($_product, 'image')->resize(338, 474).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';

Try to do the following steps, (let's say you want 150 width):

  1. Go and open default/template/catalog/product/view/media.phtml.
  2. Now On line 54 find the delete the 'width' and 'height' attributes in the tag.
  3. On the same line (54), find.

    $_image->getFile()->resize(150, 150);

All good. Simply replace one of these numbers with 0 and the image will auto scale. eg:

$_image->getFile()->resize(150, 0);

It will give you images 150 pixels wide, but the height will vary according to the original image ratio.

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM