2

我正在使用 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。所有图像都显示但需要调整它们的大小。请帮助执行此操作。

4

2 回答 2

4

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

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(56) ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
于 2012-12-18T09:55:08.237 回答
0
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"/>


}       
于 2018-04-07T04:14:37.807 回答