duanli0162 2015-11-04 20:51
浏览 17

获取产品的所有Magento图像(原始尺寸)

Right now I'm trying to loop through each of a products images, and output their fullsize image url, and the images sizes.

PHP Code

<?php foreach ($this->getGalleryImages() as $_image): ?>
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image')->getOriginalHeight(); ?>
    <?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image')->getOriginalWidth(); ?>
<?php endforeach; ?>

Trying to figure out why this returns the main images size for every image.

This code doesn't work at all

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

Neither does this...

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

Any ideas?

  • 写回答

1条回答 默认 最新

  • douke3442 2015-11-04 21:27
    关注

    Figured it out! Apparently ->getOriginalWidth and ->getOriginalHeight do not work on other main images.

    Used this to workaround it

    PHP

    <?php foreach ($this->getGalleryImages() as $_image): ?>
        <?php $fullImage = new Varien_Image($_image->getPath()); ?>
            <?php echo $this->helper('catalog/image')->init($_product, 'image', $_image->getFile()); ?>'
            <?php echo $fullImage->getOriginalWidth(); ?>
            <?php echo $fullImage->getOriginalHeight(); ?>
    <?php endforeach; ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程