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.

  • 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 Jan 4 '18 at 7:57
  • Thanks Abdul, but this isn't worked for me. Error showing "Call to a member function getUrl() on a non-object" – Satrughna Sethy Jan 4 '18 at 8:41
  • are using Magento1 & Magento2? – Abdul Jan 4 '18 at 9:03
  • I am using Magento 1 – Satrughna Sethy Jan 4 '18 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 Jan 4 '18 at 9:25
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);
}
  • This code is only showing the small sizes, but for actual size what shall i do? – Satrughna Sethy Jan 4 '18 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()
  • 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. – Satrughna Sethy Jan 4 '18 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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