简体   繁体   English

在产品查看页面(media.phtml)magento中调整图像大小的问题

[英]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. 我正在尝试在产品视图页面中调整图像的大小,但是在调整图像大小之后,左右两侧(宽度)都出现了空格,在调整大小功能中,我给了值338,474,但是它带有空格。 For that I applied function keepFrame(false) . 为此,我应用了函数keepFrame(false)

But after applying that, my image height remains same, but width changes to 271. What should I do? 但是在应用之后,我的图像高度保持不变,但是宽度变为271。我该怎么办? 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) . 我在resize(338,474)之前和之后都尝试过keepFrame(false) 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): 尝试执行以下步骤(假设您想要150宽度):

  1. Go and open default/template/catalog/product/view/media.phtml. 转到并打开default / template / catalog / product / view / media.phtml。
  2. Now On line 54 find the delete the 'width' and 'height' attributes in the tag. 现在,在第54行中,找到标记中的delete“ width”和“ height”属性。
  3. On the same line (54), find. 在同一行(54)上查找。

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

All good. 都好。 Simply replace one of these numbers with 0 and the image will auto scale. 只需将这些数字之一替换为0,图像就会自动缩放。 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. 它将为您提供150像素宽的图像,但是高度会根据原始图像比率而变化。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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