簡體   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