获取原始图片 url Magento (1.6.1.0) [英] Get original image url Magento (1.6.1.0)
本文介绍了获取原始图片 url 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
}
如您所见,我尝试了多种方法来获取原始图片网址.目前我正在使用 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()
希望这会有所帮助.
这篇关于获取原始图片 url Magento (1.6.1.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文