【问题标题】:How to resize media images in magento?如何在magento中调整媒体图像的大小?
【发布时间】:2012-12-18 06:42:59
【问题描述】:

我使用的是 magento 1.7 版本。我有一些产品图片。现在我想在详细页面中显示为滑块。我的代码如下:-

<?php if (count($_product->getMediaGalleryImages()) > 0): ?>  
<div class="more-views">

<div class="productsmallImage">
    <div id="slider2">
        <a class="buttons prev" href="javascript:;">left</a>
        <div class="viewport">                 
            <ul class="overview">            
                <?php foreach ($_product->getMediaGalleryImages() as $_image):?>
                <li>
                    <!--No lightbox on click of image-->
                  <a href="<?php echo $_image->getUrl();?>" title="<?php echo $_image->getName();?>" onclick="$('image').src = this.href; return false;">
                      <img src="<?php echo $_image->getUrl(); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
                  </a>
                </li>
                <?php endforeach; ?>
            </ul>
        </div>
        <a class="buttons next" href="javascript:;">right</a>
    </div>
</div>

在这个计数中($_product->getMediaGalleryImages()) 的值为 4。所有图像都显示但需要调整大小。请帮忙。

【问题讨论】:

    标签: e-commerce magento-1.7 magento-1.6 magento


    【解决方案1】:

    尝试使用以下结构进行图像输出:

    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(56) ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
    

    【讨论】:

      【解决方案2】:
      foreach ($_product->getMediaGalleryImages() as $image) {
      

      固定宽度为 600px

      $image_Url = Mage::helper('catalog/image')
       ->init($_product, 'image')
      ->constrainOnly(TRUE)
      ->keepAspectRatio(TRUE)
      ->keepFrame(FALSE)
      ->resize(600,null)
      ?> 
      

      固定高度为 600px

      $image_Url =  Mage::helper('catalog/image')
                    ->init($_product, 'image')
                     ->constrainOnly(TRUE)
                     ->keepAspectRatio(TRUE)
                     ->keepFrame(FALSE)
                      ->resize(null,600)
      

      以下代码将按比例调整图像大小,而不是让 图片大于指定的高度和宽度。

       $_image_Url = Mage::helper('catalog/image')
                                ->init($_product, 'image', $image->getFile())
                                ->keepFrame(true)
                                ->keepAspectRatio(TRUE)
                                ->constrainOnly(true)
                                ->resize(600,600);
      
      
      <img src="<?php echo  $_imageUrl; ?>" alt="" class="normal"/>
      
      
      }       
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-09
        • 2012-12-02
        • 1970-01-01
        • 2011-10-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多