DAddYE/vips

Black background after PNG resize with alpha channel

alehano opened this issue · 10 comments

Black background after PNG resize with alpha channel. How can I set it to white?

All libvips save operations have a background argument you can use to set the colour an alpha channel is flattened out with. For example:

$ vips copy a.png x.jpg[background=255]
$ vips copy a.png x.jpg[background="255 128 128"]

Is there an API in go code?

@jcupitt Will libvips not maintain alpha channels?

@foresmac libvips keeps the alpha if you resize png -> png.

This issue (I think?) is resizing png -> jpg. In this case, libvips defaults to a black background and if you need a different colour, you have to specify it.

@jcupitt Ah, this is apparently the exact problem we were having. Thanks for the insight!

Looks like vips is always using JPEG output: https://github.com/DAddYE/vips/blob/master/vips.go#L318

The reason is that png is petty slow and the aim of the library was to make resize fast.

@DAddYE Understandable.

But yes, it's not hard to make it work with png too ;)

I would also like to see support for keeping PNGs as PNGs 👍

Thanks for making this library!