Magento 1.9 – Image Resize Adds Black Bars Instead of Transparent

magento-1.9PHPproduct-images

I'm trying to resize my product images so they all fit in a 1:1 square. To prevent cutting off the edges I want to add whitespace, but it adds black bars instead of transparent ones. My code:

$image->quality(90);
$image->keepAspectRatio(true);
$image->keepFrame(true);
$image->keepTransparency(true);

if($height == $width) {
    $image->resize(1000, 1000);
}

$image->save($cachedImagePath);

However, it turns out like this:

image with black bars
Any ideas on how to change the black bars to white? I'm running 1.9.0.1 with the latest patches installed (up to 9767). Thanks in advance!

Best Answer

$image->constrainOnly(false);
$image->keepFrame(true);
// avoid black borders by setting background colour
$image->backgroundColor(array(255,255,255));
$image->keepAspectRatio(true);
$image->resize(1000, 1000);

Hope it will help... use backgroundColor to remove black color

Related Topic