UNPKG

magica

Version:

ImageMagick for browser and Node.js, easy setup, high level API and Command Line Interface, including WASM binary for an easy setup.

37 lines 1.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const file_1 = require("../file/file"); const main_1 = require("../main/main"); /** * Compare the two images and return true if they are equal visually. Optionally, a margin of error can be provided using `fuzz` */ function imageCompare(img1, img2, fuzz = 0.015) { return __awaiter(this, void 0, void 0, function* () { if (!img1 || !img2) { return false; } const identical = yield imageCompareNumber(img1, img2); return identical <= fuzz; }); } exports.imageCompare = imageCompare; function imageCompareNumber(img1, img2) { return __awaiter(this, void 0, void 0, function* () { const result = yield main_1.main({ inputFiles: [img1, img2], command: ['convert', img1.name, img2.name, '-resize', '256x256^!', '-metric', 'RMSE', '-format', '%[distortion]', '-compare', 'info:info.txt'], }); const n = file_1.File.asString(result.outputFiles[0]); return parseFloat(n); }); } exports.imageCompareNumber = imageCompareNumber; //# sourceMappingURL=imageCompare.js.map