获取Magento中产品图像的高度

时间:2013-01-08 02:10:22

标签: php magento

在Magento的media.phtml文件中,您可以获得第一张产品图片的图像高度:

<?php $imageWidth = $this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth(); ?>

然而,这不适用于其他产品图片(在foreach循环中):

<?php if (count($this->getGalleryImages()) > 1): ?>
<?php foreach ($this->getGalleryImages() as $_image): ?>

也没有..

<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())->getOriginalWidth(); ?>

有人有答案吗?

2 个答案:

答案 0 :(得分:3)

目录图像助手缺乏对这类操作的支持。您必须初始化图像模型并从那里获取大小。所以:

<?php foreach ($this->getGalleryImages() as $_image): ?>
  <?php $image = new Varien_Image($_image->getPath()); ?>
  <?php echo $image->getOriginalWidth(); ?>
  <?php echo $image->getOriginalHeight(); ?>
<?php endforeach; ?>

答案 1 :(得分:0)

Jernej的答案是:

$imagelink = $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile());                        

list($width, $height, $type, $attr) = getimagesize($imagelink);

echo $width;