1

I have spent more than 3 hours to search how to get the exact dimension of product image(original) size in the listing page of each product, but everyone has answered that only resize width and height. But I need the image dimension to show under the title. How can i get that?

Thanks.

7
  • Try this code: <?php $imageUrl = $block->getUrl() .'pub/media/catalog/product'. $_product->getImage(); list($width, $height) = getimagesize($imageUrl); $arr = array('height' => $height, 'width' => $width ); print_r($arr); ?>
    – Abdul
    Commented Jan 4, 2018 at 7:57
  • Thanks Abdul, but this isn't worked for me. Error showing "Call to a member function getUrl() on a non-object" Commented Jan 4, 2018 at 8:41
  • are using Magento1 & Magento2?
    – Abdul
    Commented Jan 4, 2018 at 9:03
  • I am using Magento 1 Commented Jan 4, 2018 at 9:04
  • Try this: <?php if($_product->getSmallImage()) { $imageUrl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$_product->getSmallImage(); list($width, $height) = getimagesize($imageUrl); $arr = array('height' => $height, 'width' => $width ); print_r($arr); } ?>
    – Abdul
    Commented Jan 4, 2018 at 9:25

2 Answers 2

2

Try this code:

if($_product->getSmallImage()) {
    $imageUrl=  Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product/'.$_product->getSmallImage();
    list($width, $height) = getimagesize($imageUrl);
    $arr = array('height' => $height, 'width' => $width);
    print_r($arr);
}
1
  • This code is only showing the small sizes, but for actual size what shall i do? Commented Jan 4, 2018 at 10:17
1

Check below code to get the orginial dimension

$this->helper('catalog/image')->init($_product, 'image')->getOriginalWidth()
$this->helper('catalog/image')->init($_product, 'image')->getOriginalHeight()
1
  • Thank you Abhinav, but this code is providing all values same. I am getting the output as 262 x 262 in every product. But i have uploaded different sized product images. Commented Jan 4, 2018 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.