- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些与 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
并成功。虽然我不明白什么样的图像可以重命名而不显示损坏的图像标志(超出主题)。
- app/design/frontend/base/default/catalog/product/view/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'));
Result:
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];
}
- The exception was catched in the previous code:
Mage_Catalog_Helper_Image
public function __toString()
{
...
} catch( Exception $e ) {
$url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
}
...
}
the $url became:
http://local.m.com/skin/frontend/default/default/images/catalog/product/placeholder/image.jpg
Mage_Catalog_Helper_Image
was rewritten byOnePica_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
}
最佳答案
不,这不是错误。它只是对旧 Magento 系统的遗留支持。我想知道,您是否曾经四处窥探过早期版本的 magento(如内联文档注释所引用的,< 1.1.3)?
事情的要旨在法师1.1.3之前,Mage_Catalog_Helper_Image
实例碰巧从 to-string casts 产生 URL,例如
$image = (some instance of Mage_Catalog_Helper_Image).. ;
$imageUrl = (string) $image;
__toString
可能是
protected
或
private
,我不确定,但我确定通常的做法是始终编写此魔术方法,以便在您打算重写的类中使用它,该类期望使用这种数据转换。
关于Magento:ImageCdn 错误? (很长的故事),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12056357/
我有一些与 Magento 的免费扩展有关的问题 OnePica ImageCdn . 当我上传“损坏的图像”时,前端出现损坏的图像。 好的,让我们开始长篇大论: 我注意到这是因为 ImageCdn
我是一名优秀的程序员,十分优秀!