Jimp: .rgba(false) does not work

Created on 20 Dec 2018  路  5Comments  路  Source: oliver-moran/jimp

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

bug

Most helpful comment

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.

All 5 comments

Same issue here. Any updates?

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.

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.

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

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SamuelZhaoY picture SamuelZhaoY  路  3Comments

haydenbleasel picture haydenbleasel  路  6Comments

master-of-null picture master-of-null  路  3Comments

PainKKKiller picture PainKKKiller  路  5Comments

alyyousuf7 picture alyyousuf7  路  3Comments