How to resize media images in magento?

How to resize media images in magento?

September 21, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to resize media images in magento?

Resizing Media Images in Magento

Magento provides robust functionality for managing product images, including resizing them to fit specific dimensions. To create a slideshow of your product images on the detail page, you’ll need to resize the images before displaying them.

Understanding Image Sizes

Before we get into code, let’s discuss image sizes in Magento 1.x:

  • The default thumbnail size is 75x75 pixels.
  • The small image size is 240x240 pixels.
  • The medium image size is 300x300 pixels.
  • The large image size is 1200x1200 pixels.

When you upload an image via the admin panel, Magento automatically creates these resized versions and stores them in your media directory (/media/catalog/product).

Resizing Images in Your Template

To resize images within your phtml template files, you can use the getSmallImageUrl(), getMediumImageUrl(), or getLargeImageUrl() methods provided by Magento. These methods automatically retrieve the resized version of the image.

Here’s how to modify your existing code:

<?php if (count($_product->getMediaGalleryImages()) > 0): ?>
    <div class="more-views">
        <div class="productsmallImage">
            <div id="slider2">
                <!-- ... -->
                <div class="viewport">
                    <ul class="overview">
                        <?php foreach ($_product->getMediaGalleryImages() as $_image):?>
                            <li>
                                <!--No lightbox on click of image-->
                              <a href="<?php echo $_image->getUrl();?>" title="<?php echo $_image->getName();?>" onclick="$('image').src = this.href; return false;">
                                  <img src="<?php echo $_image->getSmallImageUrl(); ?>" width="56" height="56" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" />
                              </a>
                            </li>
                        <?php endforeach; ?>
                    </ul>
                <!-- ... -->

In this updated code, we’ve replaced the original image URL call ($_image->getUrl();) with the getSmallImageUrl() method. This ensures that Magento uses the pre-resized small version of the image.

Custom Resizing with Image Resizer

If you need to create a custom size (e.g., 400x400 pixels), you can use the built-in image resizer functionality provided by Magento’s Mage_Catalog_Helper_Image class.

Here’s an example of how to do this:

$imageHelper = Mage::helper('catalog/image');
$imageWidth = 400;
$imageHeight = 400;
$resizedImageUrl = $imageHelper->init($_product, 'image')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($imageWidth, $imageHeight)->getUrl();

echo '<img src="' . $resizedImageUrl . '" width="56" height="56" />';

In this example, we create a new Mage_Catalog_Helper_Image object and use its methods to resize the image. The resize() method takes two parameters: the desired width and height.

Conclusion

Resizing images in Magento 1.x is straightforward once you understand how the built-in image resizer works. By using the provided methods like getSmallImageUrl(), getMediumImageUrl(), or creating custom sizes with the Mage_Catalog_Helper_Image class, you can efficiently manage your product images.

Remember to clear your cache after making changes to ensure the new images appear on the frontend.

For more advanced Magento development tips and best practices, check out our recent post on Optimizing Your Magento Store for Better Performance.

Magento 1 Catalog Themes Admin

Our network