How to Get Thumbnail Original Image in Magento

image

I need to get the original image for the image type attribute like the default one of thumbnail or small_image on the admin side. You can't seem to use $_prod->getMediaGalleryImages() because if the image is marks as excluded then it an image will not show up there, which makes sense since it's to excluded it from the gallery. You can do something like this

<?php
        $_prod = Mage::getModel('catalog/product')->load($product->getId());
        $types=array();
        foreach ($_prod->getMediaAttributes() as $attribute) {
            $types[] = $attribute->getAttributeCode();
        }

        echo "PROD", PHP_EOL;
        echo  "id=>",$product->getId(), PHP_EOL;
        echo  "imageTypes=>",$product->getId(), PHP_EOL;

        //var_dump($imageTypes);
        $attrImgs=array();
        foreach ($types as $type){
            $imgHelper = Mage::helper('catalog/image');
            $filename = "";
            try{
                $filename = Mage::helper('catalog/image')->init($_prod, $type);
            }catch(Exception $e){}
            echo " ==>",$type, PHP_EOL;
            $attrImgs[$type] = $filename."";//force string output
            echo "  ==>",$filename, PHP_EOL;
        }

Which will get you all the assigned images but, they are the cached url paths. Not what I want. I know the image name is in the url as /n/a/name-of-original-file/cached.jpg where name-of-original-file is the original name with out the but processing the string to get that is well not what I want to do. looking at Mage::helper('catalog/image')->init($_prod, $type); shows there is a protect var of _imageFile which is what I seem to need.

I can't seem to find out where I can grab file path or name with out having to pull it through Mage_Catalog_Helper_Image. What I want to end up with is a list of images and the type it belongs to. I have the types done, but I can only get the cached url for the image. Any ideas?

Best Answer

You can use

$product->getImageUrl();

If you just need the main image, otherwise:

$product->getMediaGallery('images');

Which will return an array, even if marked as exclude.