0

We have a script that displays PNGs uploaded to out DB on a page with a white background.

This works perfectly fine for 99% of the images.

Where it does not work is when the uploaded PNG is white-on-transparent, in which case we just see nothing but white space.

I'm wondering if there is a way to automatically detect such images and add a dark background for the div where the PNG is displayed?

Uno Mein Ame
  • 1,060
  • 5
  • 16
  • 29

1 Answers1

1

You can try to convert png to jpg using php: Similar post (Instead of saving the white backround you can set your RGB to black (0,0,0) )

Or use powerful php library where you can edit images its called Imagine
and there you can change alpha to black color For useful examples you can visit Docs

To get file extension you can use pathinfo($path, PATHINFO_EXTENSION);

DcBD
  • 46
  • 3
  • Adding the background is not the issue. The issue is figuring out whether the background should be white or black based on the content of the PNG. – Uno Mein Ame Apr 10 '19 at 20:19