douyoupingji7238 2015-06-24 18:42
浏览 18
已采纳

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

I'm developing a website for an art gallery so all of their product images have different widths and heights depending on the art piece. I want the image to display at 630px wide every time but depending on the image, extend longer down the page than others. Currently, I know that I can adjust the $bigImageX and $bigImageY of the product images from the media.php file located in

/app/design/frontend/default/theme706/template/ecommerceteam/cloud-zoom/catalog/product/view

but this is only allowing me to set a specific width and height. If I set only the height, it shrinks so that the width is the same as the height.

<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条回答 默认 最新

  • dorbmd1177 2015-06-25 18:40
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理