Programmatically get the width and height of a product image in Magento?

眉间皱痕 提交于 2020-01-24 15:29:27

问题


Inside Magento templating code I want to get the width and height of the original product image (uploaded by admin when creating product), so as to make according adjustments.

How can I do this? Thus far I have:

$this->helper('catalog/image')->init($_product, 'image')

Does this have any methods that would allow me to retrieve the original dimensions of the product image? Such as:

$this->helper('catalog/image')->init($_product, 'image')->getWidth()

Or something?

Thanks!


回答1:


Just found it in the docs: http://docs.magentocommerce.com/Mage_Catalog/Mage_Catalog_Helper_Image.html

Seems it's:

$this->helper('catalog/image')->init($_product, 'image')->getOriginalHeight()
$this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth()


来源:https://stackoverflow.com/questions/9286441/programmatically-get-the-width-and-height-of-a-product-image-in-magento

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!