Pergunta

My question is about how and when images get created inside the product image cache. Specifically, if this code is executed:

$imageTag ='<br><img src="'.Mage::helper('catalog/image')->init($product ,
                'small_image')->resize(75).'" border="0" />';

And the following directory exists with 777 permissions:

/media/catalog/product/cache/1/small_image/

But there is no 75x/ subdirectory, will that directory get created and the resized image stored at the correct place? Or does that directory need to be available (through some other process) before attempting to get the URL for the resized image using the Magento helper?

Foi útil?

Solução

Read this answer, https://magento.stackexchange.com/a/1008/361

The number within the URL doesn't represent the scale or pixel dimensions of the image - it is the store view.

All directories/files are automatically created the moment the front-end is viewed and the resize code is executed. It is that simple.

Outras dicas

That directory gets automatically created. Our developers in the frontend regularly change sizes, without creating any directory.

 <?php
               $_file_name = $cat->getThumbnail(); // Here $cat is category data array                
$_media_dir = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category' . DS;
                $cache_dir = $_media_dir . 'resize' . DS; // Here i create a resize folder. for upload new category image

if (file_exists($cache_dir . $_file_name)) {
                             $catImg =Mage::getBaseUrl('media') .  'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
                         } elseif (file_exists($_media_dir . $_file_name)) {
                             if (!is_dir($cache_dir)) {
                                 mkdir($cache_dir);
                             }

                             $_image = new Varien_Image($_media_dir . $_file_name);
                             $_image->constrainOnly(true);
                             $_image->keepAspectRatio(false);
                             $_image->keepFrame(false);
                             $_image->keepTransparency(true);
                             $_image->resize(224, 174); // change image height, width
                             $_image->save($cache_dir . $_file_name);
                             $catImg = Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . 'resize' . DS . $_file_name;
                         }
 echo  $catImg ; // display resize category thumbnail imagename
 ?>

<img src="<?php echo $catImg;  ?>"  />

I have found the problem solution Here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top