How to resize category images in Magento?

How to resize category images in Magento? I used the following code to resize product images, but I cannot use it to display category images:

$this->helper('catalog/image')->init($_product, 'small_image')->resize(170); 
+4
source share
5 answers

If I'm not mistaken, this should be:

 init($_product, 'small_image')->resize(100,100); // single parameter work with 'image' init($_product, 'image')->resize(100); // How about this $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $image->getFile())->resize(100,100); 

Here is the new code. If you tell me what extension to which, we decided quickly. If I am not mistaken, you have used the template directory image extension. So there is a function inside the inside, as shown below.

 // app/design/frontend/default/default/template/easycatalogimg/homepage.phtml <?php echo Mage::helper('easycatalogimg/image')->resize($imageUrl, $width , $height) ?> 
+5
source
  <?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 ?> 

"/">

For more details see here.

+3
source

If you want to resize category images, here is a free module based on resizing the main image. Since I struggled with this myself, I ultimately created this extension to easily resize categories of images, such as resizing a product’s image.

+2
source

If you need to resize the category image as it continues to shrink to 475 pixels wide, you can do this by removing 'width = "475" from the following template: application / design / interface / default / default / template / directory /category/view.phtml

You may also need to disable or clear the cache in the backend at: System → Cache Management → Image Cache → Clear.

From: http://www.pridedesign.ie/content/magento-resize-category-image

0
source

I understand that I am late for the party, but I had the opportunity to take a look at this recently, and using init() to resize the product images is fine, as described in the question, but you do not need to use the same function to resize one image from using a function in which the image itself (third parameter) is an optional value.

Here I did to resize the image, this is for any image:

 $model = Mage::getModel('catalog/product_image'); $model->setBaseFile('test.png'); $model->setWidth(100); $model->resize(); $model->saveFile(); echo $model->getUrl(); // generates the following url: http://example.com/media/catalog/product/cache/1//9df78eab33525d08d6e5fb8d27136e95/test.png 

If you do not want to save your image in the media directory, you can use the Varien_Image object to achieve this:

 $varienImage = new Varien_Image('test.png'); $varienImage->resize(100); $varienImage->save('var', 'test2.png'); 

save() takes the first parameter as the directory in which you want to save the new file, and the second is the name of the new file.

The steps are similar to what the init function does, in addition to dealing with a bunch of logic with the product itself.

0
source

Source: https://habr.com/ru/post/1389054/


All Articles