Magento- Resize Images on the Category Grid and List pages

Magento- Resize Images on the Category Grid and List pages

August 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento- Resize Images on the Category Grid and List pages

Resizing Product Images on Magento Category Pages

If you’re trying to resize product images on your Magento category grid or list pages, you’ve likely already discovered that editing the .phtml files isn’t enough to achieve this change. The issue lies in how Magento caches and handles image resizing.

Understanding Magento’s Image Resizing Process

Magento uses a caching system for optimized images. When an image is first accessed, it’s resized and cached based on the configuration set in the admin backend or hardcoded in the theme files like you’ve tried to do with your .phtml edits.

The cache stores the resized version of the image, and subsequent requests will serve this cached version instead of re-resizing the original image each time. This is highly efficient for performance but can cause issues when you want to manually override the size.

Clearing the Cache

You mentioned that you’ve cleared the cache already, which is a crucial step in this process. Magento uses multiple caching systems, including the full page cache and the block HTML output cache. The most common method to clear everything is through the command line:

php bin/magento cache:clean

This command clears all caches except for the DB logs. If you want to completely flush everything (which isn’t recommended in a production environment), use:

php bin/magento cache:flush

After running these commands, you should clear your browser’s cache as well.

The Role of Media Storage Configuration

Magento stores its images in the media folder and has specific rules for how it handles image resizing. The default configuration is set to create two sizes for each product image: the original (“original”), and a “small” version which is 135x135 pixels.

You can check your current media storage configuration in the admin backend at Stores > Configuration > Catalog > Product Images. Here, you can define the quality of the images and the sizes for different product types. However, changing these values won’t directly affect existing images; it will only apply to new products added after the change.

Manually Resizing Images with Varien

The Varien_Image class is Magento’s built-in image resizing library. To manually resize an image and bypass the cache, you can use this class in your .phtml files like this:

$imageHelper = $this->helper('Catalog_Catalog_Product_View');
$imageSize = 187;
$imageModel = Mage::getModel('catalog/product_media_config');

$image = $imageHelper->init($_product, 'small_image')->keepAspectRatio(true)
    ->constrainOnly(1);
$resizedImage = $imageModel->resize($image, $imageSize);

echo '<img src="' . $this->helper('catalog/image')->init($_product, 'small_image')
    ->constrainOnly(false)->keepFrame(false)->quality(85)->format('jpeg')->resize($imageSize)
    ->__toString() . '" width="' . $imageSize . '" height="auto" class="img-responsive">';

This code initializes the Varien_Image helper and manually resizes the image. The key difference is that it bypasses the standard Magento image handling process, which includes the caching mechanism.

Updating CSS for Responsive Images

You mentioned updating the CSS file to reflect your desired dimensions:

.products-grid .product-image {
  display: block;
  width: 187px;
  height: 140px;
  margin: 0 0 0px;
}

While this will ensure that the container for the image is the correct size, it won’t actually resize the image itself. The CSS can only control the layout of the element; it cannot inherently change the image file’s dimensions.

Conclusion

Resizing product images in Magento isn’t as straightforward as editing a few files. It requires a clear understanding of how the platform handles caching and image resizing.

To summarize:

  1. Always clear the cache after making changes.
  2. Use Varien_Image to manually resize images and bypass the cache if necessary.
  3. Update your CSS to ensure the container elements are sized appropriately for your desired layout.
  4. Keep in mind that any changes won’t apply retroactively; you may need to re-upload new images or run a script to process existing ones.

Remember, it’s always best practice to keep your core Magento files intact if possible. If you find yourself making significant theme modifications like this regularly, consider using a child theme or a custom extension for better maintainability and upgrade compatibility.

For more in-depth tutorials on image handling in Magento, feel free to explore our Blog where we cover advanced topics with practical examples.

Catalog Cache Database Performance

Our network