Next Webinar: Maximizing Magento - Get the Most out of Promotions. Register Today!

Magento

Open Source eCommerce Evolved

Magento Forum

   
directResize needs allow_url_fopen set true. 
 
Core
Member
 
Total Posts:  67
Joined:  2008-03-09
 

Most hosting companies set allow_url_fopen to false and for good reason.  Unfortunately this means directResize will not work in a lot of cases.

Either the full file path would need to be in getimagesize (instead of the url) or we need to use curl.  The full path method requires more setup information so I’m not sure if it’s a very good solution. 

One method using the curl library is the following:

Replace

public function directResize($img_min_w, $img_min_h, $ratio=0, $autoriseAgrandissement = false)
{
//--> Recherche des dimentions de l’image d’origine
$size = getimagesize($this);
$img_src_w = $size[0];
$img_src_h = $size[1];

With

public function directResize($img_min_w, $img_min_h, $ratio=0, $autoriseAgrandissement = false)
{
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $this->__toString());
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$file_contents = curl_exec($ch);
curl_close($ch);

if (!is_string($file_contents) || !isset($file_contents[0])) {
return $this->resize($img_min_w, $img_min_h);
}

$image = ImageCreateFromString($file_contents);

$img_src_w = imagesx($image);
$img_src_h = imagesy($image);

 
Magento Community Magento Community
Magento Community
Magento Community
 
gdoteof
Jr. Member
 
Total Posts:  22
Joined:  2008-05-21
 

where is this function at?

 
Magento Community Magento Community
Magento Community
Magento Community
 
gdoteof
Jr. Member
 
Total Posts:  22
Joined:  2008-05-21
 

well i found the file to edit: app/code/community/netambition/directresize/helper/image.php

however when i make the suggested changes i get the following error:

Warningimagecreatefromstring() [function.imagecreatefromstring]Data is not in a recognized format  in /home/amalgama/public_html/magento/app/code/community/NetAmbition/DirectResize/Helper/Image.php on line 18
Trace
:
#0 [internal function]: mageCoreErrorHandler(2, 'imagecreatefrom...', '/home/amalgama/...', 18, Array)
#1 /home/amalgama/public_html/magento/app/code/community/NetAmbition/DirectResize/Helper/Image.php(18): imagecreatefromstring('directResize(150, 150, 2)
#3 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(131): include('/home/amalgama/...')
#4 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(163): Mage_Core_Block_Template->fetchView('frontend/defaul...')
#5 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(180): Mage_Core_Block_Template->renderView()
#6 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(554): Mage_Core_Block_Template->_toHtml()
#7 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(431): Mage_Core_Block_Abstract->toHtml()
#8 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(408): Mage_Core_Block_Abstract->_getChildHtml('product_list', true)
#9 /home/amalgama/public_html/magento/app/code/core/Mage/Catalog/Block/Category/View.php(80): Mage_Core_Block_Abstract->getChildHtml('product_list')
#10 /home/amalgama/public_html/magento/app/design/frontend/default/default/template/catalog/category/view.phtml(63): Mage_Catalog_Block_Category_View->getProductListHtml()
#11 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(131): include('/home/amalgama/...')
#12 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(163): Mage_Core_Block_Template->fetchView('frontend/defaul...')
#13 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(180): Mage_Core_Block_Template->renderView()
#14 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(554): Mage_Core_Block_Template->_toHtml()
#15 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Text/List.php(37): Mage_Core_Block_Abstract->toHtml()
#16 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(554): Mage_Core_Block_Text_List->_toHtml()
#17 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(431): Mage_Core_Block_Abstract->toHtml()
#18 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(408): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#19 /home/amalgama/public_html/magento/app/design/frontend/default/default/template/page/3columns.phtml(54): Mage_Core_Block_Abstract->getChildHtml('content')
#20 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(131): include('/home/amalgama/...')
#21 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(163): Mage_Core_Block_Template->fetchView('frontend/defaul...')
#22 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Template.php(180): Mage_Core_Block_Template->renderView()
#23 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Block/Abstract.php(554): Mage_Core_Block_Template->_toHtml()
#24 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Model/Layout.php(505): Mage_Core_Block_Abstract->toHtml()
#25 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(319): Mage_Core_Model_Layout->getOutput()
#26 /home/amalgama/public_html/magento/app/code/core/Mage/Catalog/controllers/CategoryController.php(88): Mage_Core_Controller_Varien_Action->renderLayout()
#27 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(342): Mage_Catalog_CategoryController->viewAction()
#28 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(159): Mage_Core_Controller_Varien_Action->dispatch('view')
#29 /home/amalgama/public_html/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(146): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#30 /home/amalgama/public_html/magento/app/Mage.php(427): Mage_Core_Controller_Varien_Front->dispatch()
#31 /home/amalgama/public_html/magento/index.php(40): Mage::run()
#32 {main}

 
Magento Community Magento Community
Magento Community
Magento Community
 
gdoteof
Jr. Member
 
Total Posts:  22
Joined:  2008-05-21
 

line 18 is:

$image ImageCreateFromString($file_contents);

 
Magento Community Magento Community
Magento Community
Magento Community
 
darki777
Jr. Member
 
Total Posts:  25
Joined:  2008-04-08
 

Thank you very much @core, now it works fine smile
Can the Developer of this extension change his code / fix the bug?

Greetings, darki

 
Magento Community Magento Community
Magento Community
Magento Community
 
Thejosh13
Sr. Member
 
Total Posts:  152
Joined:  2008-06-23
 

Still not working says error on line 11

 
Magento Community Magento Community
Magento Community
Magento Community
 
CreedFeed
Member
 
Total Posts:  50
Joined:  2007-08-31
Milwaukee, WI
 

Instead of passing the getimagesize() function a URL, why not pass it the path to the image?

Please note that this has not been fully tested or verified for all situations but for the category viewing it seems to work for me:

Replace:

public function directResize($img_min_w$img_min_h$ratio=0$autoriseAgrandissement false)
    
{
        
//--> Recherche des dimentions de l'image d'origine
        
$size             getimagesize($this);
        
$img_src_w         $size[0];
        
$img_src_h         $size[1];

With:

public function directResize($img_min_w$img_min_h$ratio=0$autoriseAgrandissement false)
    
{
        
//--> Recherche des dimentions de l'image d'origine
        
$url            parse_url($this);
        
$cwd            getcwd();
        
$size             getimagesize($cwd $url['path']);
        
$img_src_w         $size[0];
        
$img_src_h         $size[1];

This seems to work for me, at least for the category view pages. My problem was that using Direct Size out of the box on my server was causing slowness. I pinpointed it to be because of the getimagesize() function. By pulling from the local file server versus a URL, it sped my site up dramatically.

 Signature 

-Steve
Quake 1 Resurrection

 
Magento Community Magento Community
Magento Community
Magento Community
 
Core
Member
 
Total Posts:  67
Joined:  2008-03-09
 

Actually I think this is a better idea.  Try to use the real file path in directresize rather than a URL or CURL.
This is a dramatic speed increase.

My site is temporarily within site/ ... so it didn’t work.

This worked for me, getimagesize($cwd . ‘/..’ . $url[’path’])

Will probably remove the ../ when it goes fully into production.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
40933 users|326 users currently online|87585 forum posts