Skip to content
\n

one image becomes just black.

\n

If I do:

\n
image = (image.has_alpha? ? image.flatten.composite2(image.bandsplit[3], :screen) : image)
\n

another one becomes just white.

\n

I guess I totally misunderstand the thing.

\n

UPD: Note: one image is downloaded from tg stickers, another one is a html5 base64 exported from p5js canvas after using the text and geometry primitives. I.e. none is made by me band by band so I suppose the images aren't \"corrupted\" in any way.

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hey @Nakilon,

\n

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:

\n

\"image\"

\n

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:

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

That should work for your second image too.

\n

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

","upvoteCount":1,"url":"https://github.com/libvips/ruby-vips/discussions/355#discussioncomment-4484576"}}}

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