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!

// 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 '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.