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

Error reading opacity levels from image? #134

Closed
jmitch0901 opened this issue Apr 28, 2016 · 2 comments
Closed

Error reading opacity levels from image? #134

jmitch0901 opened this issue Apr 28, 2016 · 2 comments

Comments

@jmitch0901
Copy link

jmitch0901 commented Apr 28, 2016

Hello, I am working on a small project for the Feed My Starving Children foundation. I really like the JIMP package, however I'm unsure if I'm either missing something, or the following is an error with JIMP.

Here is the following use case I'm trying to implement:

I read a SECRET-IMAGE.PNG stored on my server. I then read the RELEASABLE-IMAGE.PNG on my server. I have a mongo database which runs through 1,000,000 entries, to detect whether a pixel for that image has been bought or not. If it was bought, I reveal that pixel by writing the pixel color FROM the secret-image.png, TO the releasable-image.png.

Here is the issue:

For some reason my releasable-image.png becomes extremely blocky. I think it has something to do with not being able to read the alpha value correctly. I debugged this by logging the alpha value for each bought pixel, and every time it returned a alpha value of 255.

Here is the code:

function reloadImage(callbacks){

     return Jimp.read(imagePaths.secretPath)
    .then(function(secretPic){

        console.log("Reading secret image!");

        Jimp.read(imagePaths.mainPath)
        .then(function(releasedPic){

            console.log("Writing to Releasable image!");
            var count = 0;

            PixelSchema.find({})
              .lean()
              .stream()
              .on('data',function(pixelObj){


                var hex = pixelObj.isBought ? secretPic.getPixelColor(pixelObj.pixel.x,pixelObj.pixel.y)
                                            : 0xFFFFFFFF;

                if(pixelObj.isBought){
                  count++;
                }

                releasedPic.setPixelColor(hex,pixelObj.pixel.x,pixelObj.pixel.y);

              })
              .on('error',function(err){
                console.error("Error streaming the data!");
                console.error(err);
              })
              .on('close',function(){
                console.log('Done streaming the pixel data!');
                percentage = count / 1000000.0;
                pixelsBoughtCount = count;
                releasedPic.write(imagePaths.mainPath,function(){
                  console.log("done writing new image after bought pixels!");
                  if(callbacks){
                    return callbacks();
                  }
              });
            });
        });
    });
};`

Here is the result:

Am I missing something, or would this be an issue with JIMP? (Notice the child in the background)

SECRET-IMAGE.PNG
secret-image

RELEASABLE-IMAGE.PNG
releasable-image

@oliver-moran
Copy link
Collaborator

Thanks. I've made a test case and can repeat the issue.

I've opened an issue at jpeg-js/jpeg-js#17.

@hipstersmoothie
Copy link
Collaborator

@jmitch0901 seems to be fixed in latest master. Open another issue if you see the behavior persisting

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

No branches or pull requests

3 participants