Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discard alpha channel #1214

Closed
ghsanti opened this issue Mar 7, 2023 · 3 comments
Closed

Discard alpha channel #1214

ghsanti opened this issue Mar 7, 2023 · 3 comments
Labels

Comments

@ghsanti
Copy link

ghsanti commented Mar 7, 2023

I do not see a way to load an image and remove or discard the alpha channel from loaded images. This is useful for Deep Learning models that do not normally train using alpha.

I tried

  const buffer = await image.rgba(false).getBufferAsync(Jimp.MIME_JPEG)

but does not seem to be how you use it.
Is there any implemented or simple way to do this?

@da7a90-backup
Copy link

da7a90-backup commented Jun 2, 2023

Given a buffer of an image one way I managed to do it is:

  const flattened = await Jimp.read(buffer);

  flattened.colorType(2);

  flattened.background(0xffffffff);

the documentation doesn't really mention flattening and vaguely touches on alpha manipulation.

@da7a90-backup
Copy link

note that colorType(2) is for truecolor and colorType(0) is for grayscale and with flattened.background(0xffffffff); I set the default color of the bg pixels to white

@hipstersmoothie
Copy link
Collaborator

those are great options @da7a90-backup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants