Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize the categories images in Magento?

How to resize the categories images in Magento? I used the following code to resize product images, but I'm not able to use it for showing categories images:

$this->helper('catalog/image')->init($_product, 'small_image')->resize(170);
like image 671
balanv Avatar asked Jan 03 '12 10:01

balanv


People also ask

How do I resize an image in properties?

1. Select the photo to resize from the Windows Photo Gallery, click "Edit," from the Properties group, and then click "Resize."

How do I get small images in Magento 2?

You can retrieve small_image Url of the product. You need to instantiate the ImageFactory to load image objects using Magento\Catalog\Helper\ImageFactory. You can get Product small_image URL by product id by referring the above code.


2 Answers

If I am not mistaken, it 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 before which extension used, we were solve quickly. If I am not mistaken, you used Template Monster Catalog Image Extension. So, there is a function inside of the extension, like below.

// app/design/frontend/default/default/template/easycatalogimg/homepage.phtml
<?php echo Mage::helper('easycatalogimg/image')->resize($imageUrl, $width , $height) ?>
like image 181
Oğuz Çelikdemir Avatar answered Oct 01 '22 04:10

Oğuz Çelikdemir


 <?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 clarification see here

like image 27
user3146094 Avatar answered Oct 01 '22 04:10

user3146094