I was running into this issue with the new Magento Configurable swatches feature in 1.9:

Some of my product images are .png with a transparent background, and the color swatch images seem to default to a black background.

Swatch (auto-generated): Broken looking swatch

Product image:

Original product image

2 Answers 2


I solved this problem by calling Varien_Image::keepTransparency(true) on the before it does the resize.

Unfortunately, there's no event we can observe here, so we have to extend/override Mage_ConfigurableSwatches_Helper_Productimg::_resizeSwatchImage.

Maybe someone else (you?) can propose a more future-proof solution.


<?xml version="1.0"?>


class YourNamespace_Transparentswatch_Helper_Productimg extends Mage_ConfigurableSwatches_Helper_Productimg

     * Performs the resize operation on the given swatch image file and returns a
     * relative path to the resulting image file
     * @param string $filename
     * @param string $tag
     * @param int $width
     * @param int $height
     * @return string
    protected function _resizeSwatchImage($filename, $tag, $width, $height)
        // Form full path to where we want to cache resized version
        $destPathArr = array(
            $width . 'x' . $height,
            trim($filename, '/'),

        $destPath = implode('/', $destPathArr);

        // Check if cached image exists already
        if (!file_exists(Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $destPath)) {
            // Check for source image
            if ($tag == 'product') {
                $sourceFilePath = Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath() . $filename;
            } else {
                $sourceFilePath = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA)
                    . DS . self::SWATCH_FALLBACK_MEDIA_DIR . DS . $filename;

            if (!file_exists($sourceFilePath)) {
                return false;

            // Do resize and save
            $processor = new Varien_Image($sourceFilePath);

            // Begin additions by YourNamespace_Transparentswatch module.
            // End additions by YourNamespace_Transparentswatch module.

            $processor->resize($width, $height);
            $processor->save(Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . DS . $destPath);

        return $destPath;

  • You're right, because the swatc url are resized inside this function there is no other way to do it. I even find it something you could file on the Magento bug tracker, so they can fix it.
    – Jeroen
    Commented Mar 25, 2015 at 1:20
  • Good call! I went ahead and reported it. Commented Mar 25, 2015 at 16:27

Are there any updates on this issue for

Supposedly this issue has been repaired but I'm still experiencing it.

I tried this particular work around but it no longer seems to work on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.