Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot add image through Magento Cms wysiwyg editor

When i tried to add a image through wysiwyg editor and tried to save the page it took too long to respond i got the following error

a:5:{i:0;s:25:"Unsupported image format.";i:1;s:1001:"#0 /var/www/html/project1/lib/Varien/Image/Adapter/Gd2.php(51): Varien_Image_Adapter_Gd2->_getCallback('create')
#1 /var/www/html/project1/app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php(52): Varien_Image_Adapter_Gd2->open('http://121.0.0....')
#2 /var/www/html/project1/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Adminhtml_Cms_WysiwygController->directiveAction()
#3 /var/www/html/project1/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('directive')
#4 /var/www/html/project1/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#5 /var/www/html/project1/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#6 /var/www/html/project1/app/Mage.php(683): Mage_Core_Model_App->run(Array)
#7 /var/www/html/project1/index.php(87): Mage::run('', 'store')
#8 {main}";s:3:"url";s:150:"/index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmd0LXNsaWRlci1pbWcwMS5qcGcifX0,/key/ceed8184f5f336aafcc307f8623aff45/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";}

Even though the page gets saved i cant view the image in CMS editor

like image 851
Rohit S Avatar asked Feb 17 '23 20:02

Rohit S


2 Answers

The problem is that Magento is generating a dynamic link with admin path in it. See line 8 in your error : /index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ind5c2l3eWcvcmd0LXNsaWRlci1pbWcwMS5qcGcifX0,/key/ceed8184f5f336aafcc307f8623aff45/ - this is the link to your image, which is generated by the WYSIWYG.

As this link has no known image extension in the end, I assume, the error you got is produced.

The solution is to change just one setting in admin :

System -> Configuration -> General -> Content Management -> Use Static URLs for Media Content in WYSIWYG for Catalog to Yes

I found that this setting is checked in /app/code/core/Mage/Cms/Helper/WYSIWYG/Images.php on line 180 ( in Magento 1.7.0.2 ) and depending on that either static or dynamic links are generated.

like image 192
bogatyrjov Avatar answered Feb 26 '23 23:02

bogatyrjov


It's a Magento bug lack of consideration with specific store view.

Rewrite method getImageHtmlDeclaration() of Mage_Cms_Helper_Wysiwyg_Images, to modify source code:

$mediaPath = str_replace(Mage::getBaseUrl('media'), '', $fileurl);

to

$mediaPath = str_replace(Mage::app()->getStore($this->_storeId)->getBaseUrl('media'), '', $fileurl);
like image 37
Skyler Lan Avatar answered Feb 27 '23 01:02

Skyler Lan