Skip to content

Navigation Menu

Sign in
    • GitHub Copilot
      Write better code with AI
    • Security
      Find and fix vulnerabilities
    • Actions
      Automate any workflow
    • Codespaces
      Instant dev environments
    • Issues
      Plan and track work
    • Code Review
      Manage code changes
    • Discussions
      Collaborate outside of code
    • Code Search
      Find more, search less
    Explore
    • All features
    • Documentation
    • GitHub Skills
    • Blog
  • By company size
    • Enterprises
    • Small and medium teams
    • Startups
    • Nonprofits
    By use case
    • DevSecOps
    • DevOps
    • CI/CD
    • View all use cases
    By industry
    • Healthcare
    • Financial services
    • Manufacturing
    • Government
    • View all industries
    View all solutions
  • Topics
    • AI
    • DevOps
    • Security
    • Software Development
    • View all
    Explore
    • Learning Pathways
    • Events & Webinars
    • Ebooks & Whitepapers
    • Customer Stories
    • Partners
    • Executive Insights
    • GitHub Sponsors
      Fund open source developers
    • The ReadME Project
      GitHub community articles
    Repositories
    • Topics
    • Trending
    • Collections
    • Enterprise platform
      AI-powered developer platform
    Available add-ons
    • Advanced Security
      Enterprise-grade security features
    • GitHub Copilot
      Enterprise-grade AI features
    • Premium Support
      Enterprise-grade 24/7 support
  • Pricing

Search code, repositories, users, issues, pull requests...

Clear
    Search syntax tips

    Provide feedback

    We read every piece of feedback, and take your input very seriously.

    Saved searches

    Use saved searches to filter your results more quickly

    To see all available qualifiers, see our documentation.

    Sign in
    Sign up
    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert
    rsmbl / Resemble.js Public
    • Notifications You must be signed in to change notification settings
    • Fork 426
    • Star 4.5k
    • Code
    • Issues 27
    • Pull requests 1
    • Actions
    • Security
    • Insights
    Additional navigation options
    • Code
    • Issues
    • Pull requests
    • Actions
    • Security
    • Insights

    Commit

    Permalink
    This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
    Merge branch 'tolerance-as-option' of https://github.com/alex-chuyko/…
    Browse files Browse the repository at this point in the history
    …Resemble.js into alex-chuyko-tolerance-as-option
    • Loading branch information
    @jamescryer
    jamescryer committed Jun 20, 2021
    2 parents ea9226c + 1f5b64b commit 0c07df6
    Show file tree
    Hide file tree
    Showing 6 changed files with 43 additions and 3 deletions.
          • nodejs-tests/assets/isAntialiased/diffWithCustomTolerance.png diffWithCustomTolerance.png
        • nodejs-tests/assets/square1.png square1.png
        • nodejs-tests/assets/square2.png square2.png
      • nodejs-tests/ignore.test.js ignore.test.js
    • output.png output.png
    • resemble.js resemble.js

    There are no files selected for viewing

    Binary file added BIN +1.46 KB nodejs-tests/assets/isAntialiased/diffWithCustomTolerance.png
    View file
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added BIN +1.38 KB nodejs-tests/assets/square1.png
    View file
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    Binary file added BIN +1.44 KB nodejs-tests/assets/square2.png
    View file
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    28 changes: 28 additions & 0 deletions 28 nodejs-tests/ignore.test.js
    View file
    Original file line number Diff line number Diff line change
    Expand Up @@ -25,6 +25,34 @@ describe("ignore", () => {
    });
    });

    test("ignore antialiasing on with custom tolerance", async () => {
    const text = fs.readFileSync("./nodejs-tests/assets/square1.png");
    const textAa = fs.readFileSync("./nodejs-tests/assets/square2.png");

    return new Promise((resolve) => {
    const opts = {
    ignore: "antialiasing",
    tolerance: {
    red: 16,
    green: 16,
    blue: 16
    }
    };

    resemble.compare(text, textAa, opts, async (_x, data) => {
    expect(data.misMatchPercentage).toBe("100.00");
    const buffer = data.getBuffer();

    expect(buffer).toBeInstanceOf(Buffer);

    const comparison = fs.readFileSync("./nodejs-tests/assets/isAntialiased/diffWithCustomTolerance.png");

    expect(buffer.equals(comparison)).toBe(true);
    resolve();
    });
    });
    });

    test("ignore antialiasing off", async () => {
    const text = fs.readFileSync("./nodejs-tests/assets/text.png");
    const textAa = fs.readFileSync("./nodejs-tests/assets/textAa.png");
    Expand Down
    Binary file added BIN +1.46 KB output.png
    View file
    Loading
    Sorry, something went wrong. Reload?
    Sorry, we cannot display this file.
    Sorry, this file is invalid so it cannot be displayed.
    18 changes: 15 additions & 3 deletions 18 resemble.js
    View file
    Original file line number Diff line number Diff line change
    Expand Up @@ -960,6 +960,15 @@ var isNode = function () {
    wrapper();

    return getCompareApi(wrapper);
    },
    setupCustomTolerance: function (customSettings) {
    for (var property in tolerance) {
    if (!customSettings.hasOwnProperty(property)) {
    continue;
    }

    tolerance[property] = customSettings[property];
    }
    }
    };

    Expand Down Expand Up @@ -990,7 +999,7 @@ var isNode = function () {
    return resemble;
    }

    function applyIgnore(api, ignore) {
    function applyIgnore(api, ignore, customTolerance) {
    switch (ignore) {
    case "nothing":
    api.ignoreNothing();
    Expand All @@ -1010,6 +1019,8 @@ var isNode = function () {
    default:
    throw new Error("Invalid ignore: " + ignore);
    }

    api.setupCustomTolerance(customTolerance);
    }

    resemble.compare = function (image1, image2, options, cb) {
    Expand Down Expand Up @@ -1041,11 +1052,12 @@ var isNode = function () {
    compare.scaleToSameSize();
    }

    var toleranceSettings = opt.tolerance || {};
    if (typeof opt.ignore === "string") {
    applyIgnore(compare, opt.ignore);
    applyIgnore(compare, opt.ignore, toleranceSettings);
    } else if (opt.ignore && opt.ignore.forEach) {
    opt.ignore.forEach(function (v) {
    applyIgnore(compare, v);
    applyIgnore(compare, v, toleranceSettings);
    });
    }

    Expand Down

    0 comments on commit 0c07df6

    Please sign in to comment.

    Footer

    © 2025 GitHub, Inc.

    Footer navigation

    • Terms
    • Privacy
    • Security
    • Status
    • Docs
    • Contact
    You can’t perform that action at this time.