How to generate a sitemap.xml with image in Magento

This is good for SEO if product images include in the sitemap.xml file. We have implemented to add images URL in Magento sitemap.xml file.

file path : app/code/core/Mage/Sitemap/Model/Sitemap.php

Replace this code with existing code.

/**
* Generate products sitemap
*/
$changefreq = (string)Mage::getStoreConfig('sitemap/product/changefreq', $storeId);
$priority = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
$collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
$products = new Varien_Object();
$products->setItems($collection);
Mage::dispatchEvent('sitemap_products_generating_before', array(
'collection' => $products
));
foreach ($products->getItems() as $item) {
$image = Mage::getModel('catalog/product')->load($item->getId())->image;
$img = Mage::getModel('catalog/product')->load($item->getId())->getImageUrl();
$xml = sprintf(
'<url><loc>%s</loc><image:image><image:loc>%s</image:loc></image:image><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
htmlspecialchars($baseUrl."media/catalog/product" . $image),
$date,
$changefreq,
$priority
);
$io->streamWrite($xml);
}
unset($collection);