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

.rgba(false) does not work #681

Closed
Jimbly opened this issue Dec 20, 2018 · 5 comments
Closed

.rgba(false) does not work #681

Jimbly opened this issue Dec 20, 2018 · 5 comments
Labels
bug there is a bug in the way jimp behaves

Comments

@Jimbly
Copy link

Jimbly commented Dec 20, 2018

Expected Behavior

Expect to save the image without the alpha channel.

Current Behavior

Getting an image byte-wise re-interpretted from RGBA to RGB.

Failure Information (for bugs)

Steps to Reproduce

require('jimp').read('test.png', function (err, image) {
  image.rgba(false).write('out.png');
})

Screenshots
In (and expected out):
rgba
Actual out:
rgb

Context

  • Jimp Version: 0.6.0
  • Operating System: Windows 10
  • Node version: 8.11.3

Failure Logs

@jeremypele
Copy link

Same issue here. Any updates?

@hipstersmoothie hipstersmoothie added the bug there is a bug in the way jimp behaves label Sep 3, 2019
@potatolain
Copy link

potatolain commented Sep 10, 2019

To note, this happens if you use .getBase64 instead of .write as well.

I was able to work around it by turning alpha transparency on then explicitly setting the alpha channel for every pixel.

@Axenu
Copy link

Axenu commented Dec 20, 2019

I think I have found the problem.

It appears that the encoder for PNG files are setting both output AND input alpha channel to image.rgba(). This results in the input being read as RGB instead of RGBA which destroys the output.

The solution should be to change Jimp/packages/type-png/src/index.js:50 from
inputHasAlpha: data._rgba
to
inputHasAlpha: data.bitmap.alpha

I tried to fork it and make the change but one of the tests fail, and I am unable to figure out what the test even does. The important part for me is that the image ends up looking as I expect it to.

@panalgin
Copy link

panalgin commented Jul 2, 2020

Same happens when I try to save a png with rgba(false). The output is all messed like the attached image above user has shared

@tgrajewski
Copy link

If you're saving PNGs, then you can try the colorType() method on the image:

image.colorType(0);  // Grayscale without alpha
image.colorType(2);  // Truecolor without alpha

I'm not Jimp contributor, it's just a thing that I've found out in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug there is a bug in the way jimp behaves
Projects
None yet
Development

No branches or pull requests

7 participants