/** * Gets the product image URL, ensuring that it gets resized * @param $product One Mage_Catalog_Model_Product from a Collection * @param $storeId int which store Id this is for * @return image url, or blank if we can't get it figured out */ protected function _getResizedImage(Mage_Catalog_Model_Product $product, $storeId) { $size = $this->_helper->imageSizeForFeed($product, $storeId); try { // Image implementation doesn't save the resize filed unless it's coerced into // a string. Its (php) magic '__toString()' method is what actually resizes and saves $imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image')->constrainOnly(true)->keepAspectRatio($this->_config->getFeedImageKeepAspectRatio($storeId))->resize($size['width'], $size['height']); } catch (Exception $e) { $imageUrl = ''; Mage::log("Error sizing Image URL for {$product->getSku()}: {$e->getMessage()}"); } // $imageUrl should be the URL of a valid image or an empty string but some customers are reporting invalid URLs // in their feed so we add one last check. Make sure we really do have a valid URL or return an empty string if we don't if (!$this->_helper->isValidImage($imageUrl)) { Mage::log("Invalid image: {$imageUrl}"); $imageUrl = ''; } return $imageUrl; }