我可以让Magento的产品视图中的图像有一个设定的宽度,但是液体高度?

时间:2015-06-24 18:42:58

标签: php html image magento

我正在为艺术画廊开发一个网站,因此所有产品图片都有不同的宽度和高度,具体取决于艺术作品。我希望图像每次显示宽度为630px,但根据图像,在页面上延伸的时间比其他图像长。目前,我知道我可以从位于

的media.php文件中调整产品图片的$ bigImageX和$ bigImageY

/应用/设计/前端/默认/ theme706 /模板/ ecommerceteam /云的缩放/目录/产品/视图

但这只允许我设置特定的宽度高度。如果我只设置高度,它会缩小,使宽度与高度相同。

<div class="product-img-box">
    <script type="text/javascript" src="http://citizen.bluelotuscreative.com/skin/frontend/default/theme706/js/klass.min.js"></script>
    <script type="text/javascript" src="http://citizen.bluelotuscreative.com/skin/frontend/default/theme706/js/code.photoswipe.jquery-3.0.5.js"></script>


    <div class="product-box-customs">
        <p class="product-image">
        <img src="http://citizen.bluelotuscreative.com/media/catalog/product/cache/1/image/630x630/9df78eab33525d08d6e5fb8d27136e95/placeholder/default/Citizen_Atelier_-_Ashley_Woodson_Bailey_2__2.jpg" alt="Test Product" title="Test Product" />    </p>

    </div>
</div>

$bigImageX  = 630;
$bigImageY = ???;

<div class="product-box-customs">
    <?php if ($product->getImage() != 'no_selection' && $product->getImage()): ?>

    <p class="product-image">
        <a  href='<?php echo $this->helper('catalog/image')->init($product, 'image')->resize($bigImageWidth, $bigImageHeight);?>' class = 'cloud-zoom' id='zoom1' rel="<?php echo implode($config, ',');?>">
            <img class="big" src="<?php echo $this->helper('catalog/image')->init($product, 'image')->resize($bigImageX, $bigImageY);?>" alt='' title="<?php echo $this->htmlEscape($this->getImageLabel());?>" />
        </a>
    </p>

    <?php else: ?>
    <p class="product-image">
        <?php
        $_img = '<img src="'.$this->helper('catalog/image')->init($product, 'image')->resize($bigImageX, $bigImageY).'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
        echo $outputHelper->productAttribute($product, $_img, 'image');
        ?>
    </p>

1 个答案:

答案 0 :(得分:1)

Replace: $this->helper('catalog/image')->init($product, 'image')->resize($bigImageWidth, $bigImageHeight); With this: $this->helper('catalog/image')->init($_product, 'image') ->constrainOnly(TRUE) ->keepAspectRatio(TRUE) ->keepFrame(FALSE) ->resize($bigImageWidth,null);