phpmagento

Get original image url Magento (1.6.1.0)


I have the following piece of code:

$cProduct = Mage::getModel("catalog/product");
foreach($products_id as $product_id) {
    $product = $cProduct->load($product_id);
    //$products_image[] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"", $product);
    //$products_image[] = $product->getMediaConfig()->getMediaUrl($_product->getData('image'));
    $products_image[] = $product->getImageUrl(); //product's image url
}

As you can see, I've tried several ways to get the original image url. Currently I'm using getImageUrl(), but it retrieves the base image, which is a cropped version. How can I retrieve the original image??

Thanks in advance.

Edit: Seriously appears there isn't a function for it, been Googling for hours straight (also before posting here). So I've written my own function.

function get_original_image_url($base_image_url) {
    $exploded = explode("/", $base_image_url);
    $image_name = $exploded[count($exploded) - 1];

    $original_image_url = "http://yoursitehere.com/media/catalog/product/" . $image_name[0] . "/" .
                           $image_name[1] . "/" . $image_name;

    return $original_image_url;
}

I call it with:

$original = get_original_image_url($product->getImageUrl());

Works for me, though it isn't a nice way to do it.


Solution

  • You should use the catalog product media config model for this purpose.

    <?php
    
    //your code ...
    
    echo Mage::getModel('catalog/product_media_config')
                ->getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail()
    

    Hope this helps.