获取原始图像网址Magento(1.6.1.0) [英] Get original image url Magento (1.6.1.0)
本文介绍了获取原始图像网址Magento(1.6.1.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
$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
}
如您所见,我尝试了几种获取原始图像URL的方法.当前,我正在使用getImageUrl(),但它会检索基本图像,该图像是裁剪的版本.如何获取原始图像?
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??
提前谢谢.
严重出现似乎没有功能,已经连续搜索了几个小时(也在此之前发布).所以我写了我自己的函数.
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;
}
我这样称呼:
$original = get_original_image_url($product->getImageUrl());
为我工作,尽管这不是一个好方法.
Works for me, though it isn't a nice way to do it.
推荐答案
为此,您应该使用目录产品媒体配置模型.
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()
希望这会有所帮助.
这篇关于获取原始图像网址Magento(1.6.1.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文