Files
shaka-player/build/imageSimilarity.js
T
Joey Parrish d74841d28b build: Update screenshot-updating tools (#5298)
These tools had gotten out of sync with screenshot tests, leading to too
many image updates in the repo. This updates the tools to ensure the
same comparisons and thresholds are used in tests and when updating
screenshots.

The rename of build/pixelsChanged.js to build/imageSimilarity.js is not
detected as such by git/GitHub, so the diff is a little messy.
2023-06-13 13:00:50 -07:00

33 lines
849 B
JavaScript
Executable File

#!/usr/bin/env node
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @fileoverview
*
* A node script that uses the Jimp and ssim modules to compute if two images
* are different enough to warrant updating.
*/
const Jimp = require('jimp');
const {ssim} = require('ssim.js');
/**
* Compare two images and output the similarity between 0 and 1. Uses the same
* comparisons done in the tests through Karma.
*
* @param {string} oldPath
* @param {string} newPath
*/
async function main(oldPath, newPath) {
const oldScreenshot = await Jimp.read(oldPath);
const newScreenshot = await Jimp.read(newPath);
const ssimResult = ssim(oldScreenshot.bitmap, newScreenshot.bitmap);
console.log(ssimResult.mssim); // A score between 0 and 1.
}
main(process.argv[2], process.argv[3]);