Skip to content

Can't figure out how to properly discard the alpha channel #355

Answered by jcupitt
Nakilon asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @Nakilon,

Your first image has RGB all zero, and only has non zero values in the alpha channel. I find vipsdisp useful for looking at images like this: it will show you exactly what's in every pixel in the image:

By default, vips_flatten() will flatten against black (ie. 0), so the output is a black image on a black background :( If you flatten against 255 instead, you'll be able to see the alpha:

image = image.flatten(background: 255) if image.has_alpha?

That should work for your second image too.

Maybe the black default for flatten wasn't a great idea :(

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Nakilon
Comment options

@jcupitt
Comment options

Answer selected by Nakilon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants