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:


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


However, it turns out like this:

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

1 Answer 1

// avoid black borders by setting background colour
$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, 2018 at 8:09
  • Search on Google for HEX to RGB. It will give you RGB color code. Aug 8, 2018 at 14:11

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.