Home » Magento

Magento: Get width height of image using Varien_Image class

7 December 2009 432 views No Comment Popularity: 5% Share/Bookmark

In my previous post on getting height and width of image , I have written focusing on product image,  i.e. getting height and width of product image.

In this case, I will be showing you how to get height and width of any image in Magento. The image need not to be product image.

You can get width height of image using Varien_Image (lib/Varien/Image.php) class object.

In this example, I assume that your image is present inside media directory of your magento installation.

$imagePath = YOUR_IMAGE_PATH_LINK; // like http://example.com/media/myfolder/myimage.jpg

// changing url link of image into directory link
$dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imagePath,'/media'));

// getting image width and height
if (file_exists($dirImg)) {
	$imageObj = new Varien_Image($dirImg);
	$width = $imageObj->getOriginalWidth();
	$height = $imageObj->getOriginalHeight();
	echo $width." x ".$height;
}
else {
	echo "File doesn't exist.";
}

From Mukesh Chapagain's Blog | Post Magento: Get width height of image using Varien_Image class

Related posts:

  1. Magento: Get height and width of Image
  2. Magento: Resize Image
  3. Magento: Custom function to resize image proportionally
  4. Magento: Create Watermark Image
  5. Magento: Crop image

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.