Faster way to load media images in a product collection

addAttributeToSelect('media_gallery') is not working as media_gallery will come from complicated logic.

You can get easy media_gallery data inside at loop by loading the full product model But it will take a lot of memory in this case.

Use Backend model of media_gallery attribute & afterload of product Model

For getting media_gallery attribute value without full product load (Mage::getModel('catalog/product')->load($ProductID)) .

You can use afterLoad(), using this function call backend model of media_gallery eav attribute load the media image. This is much faster than full model load(Mage::getModel('ctalog/product')->load($ProductID))

foreach($his->getPopularCollection() as $product){
    $attributes = $product->getTypeInstance(true)->getSetAttributes($product);
    $media_gallery = $attributes['media_gallery'];
    $backend = $media_gallery->getBackend();
    $backend->afterLoad($product); 
    $mediaGallery = $product->getMediaGalleryImages();
        /* get Image one by  using loop*/
        foreach ($product->getMediaGalleryImages() as $image) {
        echo ($image->getUrl());
        }     

echo "<br/>..........................................<br/>";


}

The accepted answer works, but involves loading all the product attributes into memory when perhaps they are unnecessary.

To take a slightly more surgical approach (tested in 1.9.2.2 CE) do

$attributeCode = 'media_gallery';
$attribute = $product->getResource()->getAttribute($attributeCode);
$backend = $attribute->getBackend();
$backend->afterLoad($product);

This way you only load the media_gallery attribute itself.


I know the question is old and that it already has a correct answer, but it is not bad to recommend another method that can be useful to the community: Before $_product->getMediaGalleryImages()

You can try:

$_product->load('media_gallery');//load media gallery attributes
$mediaGallery = $_product->getMediaGalleryImages();

Taken from: https://stackoverflow.com/questions/7890616/get-product-media-gallery-images-from-a-product-collection-in-magento#23804663