Magento: Create product image sitemap

<?php
#
# include
#
require_once '/var/www/app/Mage.php';
Mage::app(0);


#
# functions
#
function print_head() {
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    echo "\n";
}

function print_url($url, $date) {
    echo "\n";
    echo "    $url\n";
    echo "    $date\n";
    echo "    monthly\n";
    echo "    0.3\n";
    echo "\n";
}

function print_foot() {
    echo "\n";
}


#
# main
#
try {
    print_head();

    $collection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToFilter('image', array('notnull' => '', 'neq' => 'no_selection'))
        ->setStoreId(1);

    foreach($collection as $product) {
        // get last product update
        $updatedAt = substr($product->getUpdatedAt(), 0, 10);

        // get main image
        $image = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());
        print_url($image, $updatedAt);

        // get additional images
        $gallery = Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();
        foreach ($gallery as $image) {
            print_url($image->getUrl(), $updatedAt);
        }
    }

    print_foot();
} catch (Exception $e) {
    Mage::printException($e);
}
?>
1