How to use the gm.compare function in gm

To help you get started, we’ve selected a few gm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github keybase / client / visdiff / src / index.js View on Github external
compareNext()
      return
    }

    const newPath = `screenshots/${commitRange[1]}/${filename}`
    if (!fs.existsSync(newPath)) {
      results[diffPath] = DIFF_REMOVED
      compareNext()
      return
    }

    const compareOptions = {
      tolerance: 1e-6, // leave a little wiggle room for antialiasing inconsistencies
      file: diffPath,
    }
    gm.compare(oldPath, newPath, compareOptions, (err, isEqual) => {
      if (err) {
        console.log(err)
        process.exit(1)
      }
      results[diffPath] = isEqual ? DIFF_SAME : DIFF_CHANGED
      compareNext()
    })
  }
  compareNext()
github argos-ci / image-difference / src / imageDifference.js View on Github external
},
          (err, Boolean, equality) => {
            if (err) {
              reject(err)
              return
            }

            accept(equality)
          }
        )
        break

      case 'graphicsmagick': {
        // http://www.graphicsmagick.org/GraphicsMagick.html
        // https://github.com/aheckmann/gm/blob/master/lib/compare.js
        gm.compare(
          actualFilename,
          expectedFilename,
          {
            highlightColor: 'RED',
            highlightStyle: 'Assign',
            file: diffFilename,
          },
          (err, Boolean, equality) => {
            if (err) {
              reject(err)
              return
            }

            accept(equality)
          }
        )
github oaeproject / Hilary / packages / oae-preview-processor / lib / processors / link / default.js View on Github external
puppeteerHelper.getImage(contentObj.link, imgPath, screenShottingOptions, err => {
          if (err) {
            log().error({ err, contentId: ctx.contentId }, 'Could not generate an image');
            return callback(err);
          }

          // If the image is solid white don't attach it as a screenshot
          gm.compare(
            imgPath,
            path.resolve(__dirname, '../../../static/link/blank.png'),
            0,
            (err, isEqual, equality, raw) => {
              if (err) {
                log().error({ err, contentId: ctx.contentId }, 'Could not compare image');
                return callback(err);
              }

              log().trace({ contentId: ctx.contentId, equality, raw });

              if (isEqual) {
                log().info({ contentId: ctx.contentId }, 'Not attaching blank screenshot');
                return callback();
              }
github gemini-testing / looks-same / benchmark / diff.js View on Github external
bench('gm', function(next) {
            gm.compare(
                refImage,
                currImage,
                {
                    file: path2,
                    highlightStyle: 'assign',
                    highlightColor: '"#ff00ff"'
                },
                next
            );
        });
    });
github joshua-gould / canvas2pdf / test / diff.images.js View on Github external
promises.push(new Promise(function (resolve, reject) {
      gm.compare(file1, file2, {tolerance: 0.05}, function (err, isEqual, mismatch, raw, path1, path2) {
        if (err) {
          reject(err);
        }
        assert.ok(mismatch < 0.01, item + ' ' + mismatch);
        var file1 = 'test/img/png/' + item;
        var file2 = 'test/img/pdf-to-png/' + item;
        html.push('<div style="border-bottom:1px solid LightGrey;">');
        html.push('<p>' + item + ' - ' + mismatch + '</p>');
        html.push('<img src="' + file1 + '" alt="' + item + '">');
        html.push('<img src="' + file2 + '" alt="' + item + '">');
        html.push('</div>');
        resolve();
      });
    }));
github craigtaub / snapandcompare / functions.js View on Github external
runComparison : function(item, err) {
      //compare Master with diff 
      gm.compare(config.screens+item+".jpg", config.screens+item+".diff.jpg", function (err, isEqual, equality, raw) {
        if (err) throw err;
        if (equality > 0) {
          //images not the same, FAIL.
          console.log("FAILED Diff bp:". red , item);
          console.log("FAILED equality rate:" . red , equality , "%" . red);
          //create .fail
          functions.createFail(item);
        } else {
          //no change, PASS.
          console.log("PASSED Diff bp:" . green , item);
        }
      });
    },
    createFail : function(item) {
github thingsinjars / Hardy / features / support / gm-image-utils.js View on Github external
exports.createImageDiff = function(imagePath1, imagePath2, targetImagePath, callback) {

    gm.compare(imagePath1, imagePath2, {
        file: targetImagePath
    }, function(err, isEqual, equality, raw) {

        if (err) {
            callback(err);
        } else {
            callback();
        }
    });
};
github oblador / loki / packages / diff-graphics-magick / src / create-graphics-magick-differ.js View on Github external
return new Promise((resolve, reject) => {
      gm.compare(
        path1,
        path2,
        { ...instanceConfig, file: diffPath },
        (err, isEqual) => {
          if (err) {
            if (typeof err === 'string') {
              reject(new Error(err));
            } else {
              reject(err);
            }
          } else {
            if (isEqual) {
              fs.remove(diffPath);
            }
            resolve(isEqual);
          }
github craigtaub / snapandcompare / functions.js View on Github external
createFail : function(item) {
        var options = {
          highlightColor: 'yellow',
          file: config.screens+item+'.fail.jpg'
        };
        //will overwrite current .fail if necessary.
        gm.compare(config.screens+item+".jpg", config.screens+item+".diff.jpg", options, function (err) {
          if (err) throw err;
        });
    }
}

gm

GraphicsMagick and ImageMagick for node.js

MIT
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis