Black and white background with GD library

images php coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
musicmouse
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Jan 04, 2019 5:04 am

Fri Jan 04, 2019 5:26 am

I have a jpg image with a background that is - depending on the conditions - black or white. As far as I understand from the internet this comes because the image was derived from another format (like png) where this "color" was transparent.

Now I have at the moment an image processing routine that supports both gd and Imagick. When I process certain images with Imagick I get a white background. However, when I do the same with gd I get a black background. I would like to have a white background with gd too. What could this be?

See for example this image: http://bilbil.com/img/p/9/1/5/6/9156.jpg

In my browser it gives a black background.But processed with Imagick this turns white:

http://www.bilbil.com/9156-thickbox_def ... jarige.jpg
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 854
Joined: Mon Feb 22, 2016 5:52 pm

Fri Jan 04, 2019 1:16 pm

Yes you can change the background colour, but it's not called background since you draw parts of an image to a position on the drawing area, as such background does not exist - it sounds complicated but isn't, e.g. you draw lines, cirlces etc.. after setting their outline and fill colours.
User avatar
hyper
php-forum GURU
php-forum GURU
Posts: 854
Joined: Mon Feb 22, 2016 5:52 pm

Fri Jan 04, 2019 1:18 pm

On another note, if your background is transparent, you can change the background by using css, i.e. by changing the background colour of the page that the image is on.
Post Reply