繁体   English   中英

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

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

我正在尝试在产品视图页面中调整图像的大小,但是在调整图像大小之后,左右两侧(宽度)都出现了空格,在调整大小功能中,我给了值338,474,但是它带有空格。 为此,我应用了函数keepFrame(false)

但是在应用之后,我的图像高度保持不变,但是宽度变为271。我该怎么办? 下面是我的代码。

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

我在resize(338,474)之前和之后都尝试过keepFrame(false) resize(338,474) 拜托,如果有人可以帮助我。

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

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

尝试执行以下步骤(假设您想要150宽度):

  1. 转到并打开default / template / catalog / product / view / media.phtml。
  2. 现在,在第54行中,找到标记中的delete“ width”和“ height”属性。
  3. 在同一行(54)上查找。

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

都好。 只需将这些数字之一替换为0,图像就会自动缩放。 例如:

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

它将为您提供150像素宽的图像,但是高度会根据原始图像比率而变化。

希望能有所帮助。

暂无
暂无

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

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