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);
1. Select the photo to resize from the Windows Photo Gallery, click "Edit," from the Properties group, and then click "Resize."
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.
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) ?>
<?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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With