6

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?

  • 1
    It will automatically create missing folders, you don't need to create any folder in cache folder. – user55997 Aug 7 '17 at 23:53
5

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.

3

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

-3
 <?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

  • 1
    How is that an answer to the question? What does the code do? Which problem does it even attempt to solve? – Fabian Schmengler Jun 20 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.