Magentoの無料エクステンションOnePica ImageCdnに関連する質問があります。Magento:ImageCdnバグ? (ロングストーリー)
「破損画像」をアップロードしたときにフロントエンドに壊れた画像が表示されます。
[OK]を、のは、長い話を始めましょう:
を、私はそれが理由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')); ?>
結果::私はそれがPreview
を使用して開いたとき、それは良く見えるので、私は結果に驚きました。もちろん
Array ( [0] => 200 [1] => 200 [2] => 6 [3] => width="200" height="200" [bits] => 24 [mime] => image/x-ms-bmp )
(マックOSX上)
- その後、私は最初の2バイト、バイナリエディタを使用してそれを開くがある:BMPの識別子
- 私は製品のイメージを.BMPアップロードしようとしている
BM
- >失敗した、画像 - を選択することはできません私はアップロードする私の同僚を尋ねそれも(Ubuntu上で)、彼はファイルタイプの選択を「任意のファイル」に変更することができました。 「ファイルのアップロード」をクリックすると、エラーメッセージにそのファイルの種類が許可されていないことが示されます。
- 私の考えは、管理者が
.bmp
の画像をアップロードしようとしましたが、失敗しました。その後、名前を.jpeg
に変更して成功しました。私はそれがどのような画像の名前を変更することはできません壊れたイメージのロゴ(トピックの外)を表示せずに取得しますが。 - これらのシナリオは例外を引き起こし、私がトレースしたものを分解します。コードの
トレース:
- アプリ/設計/フロントエンド/ベース/デフォルト/カタログ/製品/ビュー/メディア。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');
?>
- 、私はその画像のURLを使用して生成される知っている:
$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;
}
- でトリガエラー。コードの一部では、それが最終的に到達します:
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];
}
- 例外は、前のコードでcatchedた:
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
- だから、それはプレースホルダ画像の権利を生成している必要がありますか? (ImageCdn拡張子なし)
- いいえ、
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
}
によって書き換えられたので: 誰もが何を知っていますそのコードの目的は何ですか?私は上記の彼らのコメントの意味は何か分かりません。 本当にバグですか、それとも私の間違った解釈ですか?
問題は、 'OnePica_ImageCdn_Helper_Image'は、' parent :: __ toString(); 'に例外が発生しても常に$ this - > _ getModel() - > getUrl()を返します。 '__toString'関数で例外が発生した場合、' OnePica_ImageCdn_Helper_Image'のために私のケースでは発生しなかった '$ url = Mage :: getDesign() - > getSkinUrl($ this-> getPlaceholder()); – ivantedja