Example #1
0
export async function savePngDiff(file: string, png: PNG): Promise<string> {
    const data = PNG.sync.write(png);
    const outputDir = path.resolve(process.cwd(), './build/test-output/integration');
    const diffPath = path.resolve(outputDir, file);

    await fs.mkdir(outputDir, { recursive: true });
    await fs.writeFile(diffPath, data);

    return diffPath;
}
	private _loadImage(image: ImageReference): Promise<{
		png: PNG,
		metadata: ImageMetadata
	}> {
		const loadPromise = (typeof image === 'string') ?
			this._loadPng(image) : Promise.resolve(PNG.sync.read(image));

		return loadPromise
			.then(function (png: PNG) {
				return {
					png,
					metadata: {
						height: png.height,
						width: png.width
					}
				};
			});
	}
function decodePng(path) {
  const buffer = fs.readFileSync(path);
  return PNG.sync.read(buffer);
};
Example #4
0
export async function readPng(file: string): Promise<PNG> {
    const data = await fs.readFile(path.resolve(process.cwd(), file));
    return PNG.sync.read(data);
}
Example #5
0
export async function writePng(file: string, frame: Uint8Array, decoder: Decoder): Promise<void> {
    const png = frameToPng(frame, decoder);
    const data = PNG.sync.write(png);

    await fs.writeFile(path.resolve(process.cwd(), file), data);
}
Example #6
0
function write_png(file, image) {
  const img = new PNG({width: image.width, height: image.height});
  img.data = image.data;
  fs.writeFileSync(file, PNG.sync.write(img));
}