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

getPixelColor returns no hex #1116

Open
mimeie opened this issue Jan 1, 2023 · 3 comments · May be fixed by #1296
Open

getPixelColor returns no hex #1116

mimeie opened this issue Jan 1, 2023 · 3 comments · May be fixed by #1296
Labels
bug there is a bug in the way jimp behaves help wanted

Comments

@mimeie
Copy link

mimeie commented Jan 1, 2023

Expected Behavior

return the hex value of a green pixel. in this example from: https://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG

following code is used:

Jimp.read('https://upload.wikimedia.org/wikipedia/commons/d/de/Color-Green.JPG', (err, green) => {
   if (err) throw err;
   var color = green.getPixelColor(20, 20);   
   console.log('getpixelcolor ?: ' + color); 
   console.log(Jimp.intToRGBA(color)); 
   console.log('getpixelcolor hex:' + color.toString(16));
});

Current Behavior

I get a Pixel Color in decimal as a return value. which is some kind of magenta.
The RGB Conversion seems fine, just the "a" value cannot be correct as far as I know

this is the log:

21:50:23.023 | info | javascript.0 (4257) script.js.common.Garagentor: getpixelcolor ?: 16712191
21:50:23.024 | info | javascript.0 (4257) script.js.common.Garagentor: {'r':0,'g':255,'b':1,'a':255}
21:50:23.025 | info | javascript.0 (4257) script.js.common.Garagentor: getpixelcolor hex:ff01ff

Failure Information (for bugs)

Steps to Reproduce

described above

Screenshots

Context

  • Jimp Version: newest
  • Operating System: Linux
  • Node version: 14.21.0

Failure Logs

i don't have anything more

@hipstersmoothie
Copy link
Collaborator

If anyone wants to submit a PR to fix I'm able to review and merge!

@hipstersmoothie hipstersmoothie added help wanted bug there is a bug in the way jimp behaves labels Feb 4, 2023
@SelfDevTV
Copy link

SelfDevTV commented Jul 3, 2024

EDIT: I know the solution and will send a PR @hipstersmoothie

I needed that library for exact that reason :D i have the same bug.
The images look like that:

Top left small image is the original, the big one is the same but crafted via getPixelColor:

image

@SelfDevTV SelfDevTV linked a pull request Jul 3, 2024 that will close this issue
@hipstersmoothie
Copy link
Collaborator

Is this actually an issue? I just wrote a script and everything seems to work correctly

import { Jimp, intToRGBA } from "jimp";
import { promises as fs } from "fs";

const buffer = await fs.readFile("test.png");
const image = new Jimp({
  width: 100,
  height: 100,
  color: 0x01ff00ff,
});

const copy = new Jimp({
  width: image.bitmap.width,
  height: image.bitmap.height,
  color: 0xffffffff,
});

image.scan((x, y) => {
  const color = image.getPixelColor(x, y);
  console.log(intToRGBA(color)); // prints: { r: 1, g: 255, b: 0, a: 255 }
  copy.setPixelColor(color, x, y);
});

await copy.write("./output.png");

The resulting image

output

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 help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants