1

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!

5
$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

  • what if we need another color? what value we need to change in that backgroundColor(array(255,255,255)) ? Thanks – fudu Aug 8 '18 at 8:09
  • Search on Google for HEX to RGB. It will give you RGB color code. – Abhishek Panchal Aug 8 '18 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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