Uno Mein Ame
Uno Mein Ame

Reputation: 1090

Automatically add dark background to white-on-transparent PNGs

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?

Upvotes: 0

Views: 120

Answers (1)

DcBD
DcBD

Reputation: 46

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);

Upvotes: 1

Related Questions