question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.rgba(false) does not work

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

3reactions
tgrajewskicommented, Jul 17, 2020

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.

1reaction
Axenucommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receive incorrect alpha channel when convert rgba color to hex
Using a bitwise | (or) operator on a floating-point value does not make sense. You'll have to use ~~(achannel * 255) to get...
Read more >
color rgba doesn´t work anymore on new computer - CSS-Tricks
Recently got new computer(Windows 8, Firefox 37.0 and newest version of Opera and Chrome)and the background-color using rgba values doesn't show ...
Read more >
rgba() - CSS: Cascading Style Sheets - MDN Web Docs - Mozilla
The rgba() functional notation expresses a color according to its red, green, and blue components. An optional alpha component represents ...
Read more >
Untitled
markdownlint-disable no-inline-html --> <details open> <summary><b>RGBA</b> Color Space</summary> ```ts // note that the import name can be anything ...
Read more >
HTML RGB and RGBA Colors - W3Schools
In HTML, a color can be specified as an RGB value, using this formula: ... is a number between 0.0 (fully transparent) and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found