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

Threshold Plugin #352

Merged
merged 5 commits into from
Sep 5, 2018
Merged

Threshold Plugin #352

merged 5 commits into from
Sep 5, 2018

Conversation

brownrw8
Copy link
Contributor

Add "threshold" method to image. I believe this is useful as a simplified method for processing scanned drawings, signatures, etc. I've used a couple other methods for this but I always end up having to chain multiple calls/set up variables to get the same effect.

var {Jimp, getTestDir} = require("./test-helper");

describe("Threshold", function () {

    this.timeout(15000);

    var originalRenditionPath = getTestDir() + "/samples/hands.jpg";
    var lighterRenditionPath = getTestDir() + "/samples/threshold-samples/hands_mx200_rp255.jpg";

    var originalRendition, lighterRendition;
    before((done)=> {
        var imgs = [];
        imgs.push(Jimp.read(originalRenditionPath));
        imgs.push(Jimp.read(lighterRenditionPath));
        Promise.all(imgs).then((loadedImgs)=> {
            originalRendition = loadedImgs[0];
            lighterRendition = loadedImgs[1];
            done();
        }).catch(done);
    });

    it("defines default threshold for lighter backgrounds", ()=> {
        var transformedOriginalRendition = originalRendition.threshold(200, 255);
        transformedOriginalRendition.hash().should.be.equal(lighterRendition.hash());
    });

});

@edi9999
Copy link
Contributor

edi9999 commented Jan 9, 2018

Looks good to me.

The only thing I don't like that much is the autoGrayscale

I find it better to let the users be more explicit.

The fact that the API is chainable makes things easy too :

image.grayScale(...).threshold(...)

So I suggest to remove the autoGrayscale parameter.

@hipstersmoothie hipstersmoothie added enhancement a request for a new feature or change in behavior plugin-candidate labels Aug 4, 2018
@hipstersmoothie hipstersmoothie removed the enhancement a request for a new feature or change in behavior label Sep 1, 2018
@hipstersmoothie
Copy link
Collaborator

@edi9999 I have updated this PR and added threshold as a plugin. I think keeping the autogreyscale is fine since it helps get better output from scan.

@hipstersmoothie hipstersmoothie added the internal Changes only affect the internal API label Sep 3, 2018
@hipstersmoothie hipstersmoothie changed the title Add "threshold" method to image Threshold Plugin Sep 3, 2018
@edi9999 edi9999 merged commit f7a64aa into jimp-dev:master Sep 5, 2018
@edi9999
Copy link
Contributor

edi9999 commented Sep 5, 2018

Ok, fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Changes only affect the internal API plugin-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants