2

I am using a custom magento template which has a lightbox on the product page. I can set the max width/height for the lightbox in the config as a percentage of the screen (ie 95%). The problem is it then uses this as the default value so even it is is a really small image it will stretch it out to 95% of the screen and cause the image to pixelate.

I would like it to use this percentage as a maximum only but if the actual image is smaller than this then it would use the actual image dimensions.

I have found a file with this code which I think I may need to edit but I am not sure how to go about this in Magento:

<?php
    $maxWidth   = $zoomHelper->getCfg('lightbox/max_width');
    $maxHeight  = $zoomHelper->getCfg('lightbox/max_height');
    $cfg = '';
    if ($maxWidth)
        $cfg .= ", maxWidth:'{$maxWidth}'";
    if ($maxHeight)
        $cfg .= ", maxHeight:'{$maxHeight}'";
?>

Any ideas?

4

1 回答 1

1

我这样做的方法是加载相对较大的图像作为基本产品图像。当产品/视图呈现时,构建一个 js 对象,其中包含大图像的 url 以及您需要的任何缩略图。然后,您的灯箱应使用 js 对象作为数据源。

媒体.phtml

<script> var images = {};</script>

<?php $_images = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages(); ?>
<?php if($_images){?>            
    <?php $i=0; foreach($_images as $_image){ $i++; ?>
        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(108,90); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel());?>" title="<?php $this->htmlEscape($_image->getLabel());?>" /><?php } ?>

        <script> images.bigsrc = "<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->resize(800,800); ?>"  </script>
    <?php } ?>

然后,您有一个 js 对象,其中包含您需要的任何大小图像的 url。将其传递到灯箱/花式箱等。

您肯定必须根据您的需要对其进行定制 - 主要是在创建您可以使用的 js 对象方面。

有关在法师中调整图像大小的一些信息:http: //www.magthemes.com/magento-blog/customize-magentos-image-resize-functionality/

于 2013-02-03T00:32:30.407 回答