我有一些与Magento的免费延期相关的问题OnePica ImageCdn。
当我上传“损坏图像”时,前端出现损坏的图像。
好的,让我们开始讲故事:
我注意到它是因为ImageCdn扩展和“腐败图像”而发生的。
在ImageCdn代码的某些部分:
OnePica_ImageCdn_Helper_Image
/**
* In older versions of Magento (<1.1.3) this method was used to get an image URL.
* However, 1.1.3 now uses the getUrl() method in the product > image model. This code
* was added for backwards compatibility.
*
* @return string
*/
public function __toString()
{
parent::__toString();
return $this->_getModel()->getUrl();
}
我的问题是,有人知道该代码的目的是什么?
我不明白他们上面评论的含义是什么。
我认为这是一个错误,因为它总是return $this->_getModel()->getUrl();
真的是一个错误,还是我错误的解释?
这是我到目前为止所做的:
dummy.jpeg
<?php print_r(getimagesize('dummy.jpeg')); ?>
结果:
Array ( [0] => 200 [1] => 200 [2] => 6 [3] => width="200" height="200" [bits] => 24 [mime] => image/x-ms-bmp )
当然我对结果感到惊讶,因为当我使用Preview
打开它时看起来不错(在Mac OSX上)
BM
这是BMP的标识符.bmp
图片但失败了。然后他将其重命名为.jpeg
并成功。虽然我没有得到它可以重命名什么样的图像而不显示破损的图像标识(超出主题)。跟踪代码:
- 应用程序/设计/前端/碱/默认/目录/产品/视图/ media.phtml
<?php
$_img = '<img id="image" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" title="'.$this->htmlEscape($this->getImageLabel()).'" />';
echo $_helper->productAttribute($_product, $_img, 'image');
?>
$this->helper('catalog/image')->init($_product, 'image')
Mage::log((string)$this->helper('catalog/image')->init($_product, 'image'));
结果:
http://local.m.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/d/u/dummy.jpeg
- Mage_Catalog_Helper_Image
public function __toString()
{
try {
if( $this->getImageFile() ) {
$this->_getModel()->setBaseFile( $this->getImageFile() );
} else {
$this->_getModel()->setBaseFile( $this->getProduct()->getData($this->_getModel()->getDestinationSubdir()) );
}
if( $this->_getModel()->isCached() ) {
return $this->_getModel()->getUrl();
} else {
if( $this->_scheduleRotate ) {
$this->_getModel()->rotate( $this->getAngle() );
}
if ($this->_scheduleResize) {
$this->_getModel()->resize();
}
if( $this->getWatermark() ) {
$this->_getModel()->setWatermark($this->getWatermark());
}
Mage::log('pass');
$url = $this->_getModel()->saveFile()->getUrl();
Mage::log('not pass');
}
} catch( Exception $e ) {
$url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
}
return $url;
}
$this->_getModel()->saveFile()->getUrl()
中触发的错误。在代码的某些部分,它最终将达到:Varien_Image_Adapter_Gd2
private function _getCallback($callbackType, $fileType = null, $unsupportedText = 'Unsupported image format.')
{
if (null === $fileType) {
$fileType = $this->_fileType;
}
if (empty(self::$_callbacks[$fileType])) {
//reach this line -> exception thrown
throw new Exception($unsupportedText);
}
if (empty(self::$_callbacks[$fileType][$callbackType])) {
throw new Exception('Callback not found.');
}
return self::$_callbacks[$fileType][$callbackType];
}
- 上一个代码中包含了异常:
Mage_Catalog_Helper_Image
public function __toString()
{
...
} catch( Exception $e ) {
$url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
}
...
}
$ url成为: http://local.m.com/skin/frontend/default/default/images/catalog/product/placeholder/image.jpg
Mage_Catalog_Helper_Image
被重写了OnePica_ImageCdn_Helper_Image
public function __toString()
{
parent::__toString(); //the result is http://local.m.com/skin/frontend/default/default/images/catalog/product/placeholder/image.jpg but no variable store/process its value
return $this->_getModel()->getUrl(); //in the end it will return http://local.m.com/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/d/u/dummy.jpeg
}
如果你们都忘记了这个问题: 有人知道那段代码的目的是什么?我不明白他们上面评论的含义是什么。 它真的是一个错误,还是我错误的解释?
答案 0 :(得分:0)
不,这不是一个错误。它只是旧Magento系统的传统支持。我想知道,你有没有想过窥探早期版本的magento(如内联文档评论引用,&lt; 1.1.3)?
问题的要点是在Mage 1.1.3之前,Mage_Catalog_Helper_Image
实例碰巧从to-string强制转换生成URL,例如。
$image = (some instance of Mage_Catalog_Helper_Image).. ;
$imageUrl = (string) $image;
__toString
可能是protected
或private
,我不确定,但我确定通常的做法是始终编码此魔术方法以便使用它在一个类中,你想要重写一些预期使用这种数据转换的东西。