Magento - Removing the black background from automatic thumbnails

I found a workaround for this.
 The side effect is that the class used for image resize
will fill all images with white
(even transparent ones), but this doesn't realy affect
Magento since it doesn't use transparent fill anyway.
 So to solve the issue do this:
  1. Go to lib\Varien\Image\Adapter\Gd2.php in your magento folder
  2. Find this line
    $this->_fillBackgroundColor($newImage);
    and replace it with this line
    $this->_fillBackgroundColor($newImage,$frameWidth,$frameWidth);
  3. Find this line
    private function _fillBackgroundColor(&$imageResourceTo)
    and replace it with this
    private function _fillBackgroundColor(&$imageResourceTo,$w,$h)
  4. Find this code
    if (!imagefill($imageResourceTo, 0, 0, $color)) {
        throw new Exception("Failed to fill image background with color {$r} {$g} {$b}.");
    }
    and replace it with this
    imagefilledrectangle($imageResourceTo,0,0,$w,$h,$color);
That is it. The problem comes from the PHP function imagefill in Gd2 not working on some setings. This is a workaround using imagefilledrectangle, and worked for me. Hope it solves your problem too.


Thanks
Magento Group!

Comments