2

for our slider we want to detect the image size/width to set the attribute correctly

Now we use

$_img = Mage::getBaseUrl('media') . $s['image'];
$_imgsize = getimagesize($_img);

Only recently realizing that this code generates a request via http

question: how can we get the imagesize through the server directly? (what do we need to feed getimagesize as directory) - or is there a better way?

1
  • getOriginalSizeArray() in catalog/Helper/Image.php returns the image size.May be this helps you. Commented Nov 28, 2014 at 9:57

3 Answers 3

1

You could use the GD image class. Read more about that on php.net.

$image = imagecreatefromjpeg(Mage::getBaseDir('media') . $s['image']);
$width = imagesx(image);
$height = imagesy(image);

Although in my opinion this is too heavy to do at run time and a waste of server resources. Could you expand on what you are trying to accomplish?

2
  • Set the width and height attribute in HTML for the image (instead of leaving it blank)
    – snh_nl
    Commented Nov 28, 2014 at 9:41
  • it's a bit of a resource heavy operation just to set the width and height. You might want to reconsider Commented Nov 28, 2014 at 9:59
1

Use getBaseDir() instead of getBaseUrl().

This should work:

    $_imgsize = getimagesize(Mage::getBaseDir('media') . DS . $s['image']);
0

Can also use Varien_Image class:

$path = Mage::getBaseDir('media') ... ;
$image = new Varien_Image($path);
$x = $image->getOriginalWidth();
$y = $image->getOriginalHeight();

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.