How to use the pngjs.PNG.sync function in pngjs

To help you get started, we’ve selected a few pngjs 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 Daivuk / tddod / contentProcessor / main.js View on Github external
static const int WAYPOINT_COUNT = ${nodes.length};

`

fileData += `static const Position AIR_WAYPOINTS[] = {
    {${startPos.x}.5f, ${startPos.y}.5f},
    {${endPos.x}.5f, ${endPos.y}.5f}
};

static const int AIR_WAYPOINT_COUNT = 2;

`

// Generate waves
let waves = []
png = PNG.sync.read(fs.readFileSync("rawAssets/waves.png"));
for (let y = 0; y < png.height; ++y)
{
    let x = 0
    let wave = []
    for (; x < png.width; ++x)
    {
        let k = (y * png.width + x) * 4
        let r = png.data[k + 0];
        let g = png.data[k + 1];
        let b = png.data[k + 2];

        if (x == 0 && r == 0 && g == 0 && b == 0) break

        if (r == 255 && g == 0 && b == 255)
        {
            wave.push({
github N0taN3rd / chrome-remote-interface-extra / test / helpers / goldenHelper.js View on Github external
function compareImages (actualBuffer, expectedBuffer, mimeType) {
  if (!actualBuffer || !(actualBuffer instanceof Buffer)) {
    return { errorMessage: 'Actual result should be Buffer.' }
  }

  const actual =
    mimeType === 'image/png'
      ? PNG.sync.read(actualBuffer)
      : jpeg.decode(actualBuffer)
  const expected =
    mimeType === 'image/png'
      ? PNG.sync.read(expectedBuffer)
      : jpeg.decode(expectedBuffer)
  if (expected.width !== actual.width || expected.height !== actual.height) {
    return {
      errorMessage: `Sizes differ: expected image ${expected.width}px X ${
        expected.height
      }px, but got ${actual.width}px X ${actual.height}px. `
    }
  }
  const diff = new PNG({ width: expected.width, height: expected.height })
  const count = pixelmatch(
    expected.data,
    actual.data,
    diff.data,
    expected.width,
    expected.height,
    { threshold: 0.1 }
github puppeteer / puppeteer / test / golden-utils.js View on Github external
function compareImages(actualBuffer, expectedBuffer, mimeType) {
  if (!actualBuffer || !(actualBuffer instanceof Buffer))
    return { errorMessage: 'Actual result should be Buffer.' };

  const actual = mimeType === 'image/png' ? PNG.sync.read(actualBuffer) : jpeg.decode(actualBuffer);
  const expected = mimeType === 'image/png' ? PNG.sync.read(expectedBuffer) : jpeg.decode(expectedBuffer);
  if (expected.width !== actual.width || expected.height !== actual.height) {
    return {
      errorMessage: `Sizes differ: expected image ${expected.width}px X ${expected.height}px, but got ${actual.width}px X ${actual.height}px. `
    };
  }
  const diff = new PNG({width: expected.width, height: expected.height});
  const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.1});
  return count > 0 ? { diff: PNG.sync.write(diff) } : null;
}
github image-js / fast-png / __tests__ / encode.js View on Github external
function checkPngJs(data, values) {
    const img = PNG.sync.read(Buffer.from(data, data.byteOffset, data.length));
    var newValues = Object.assign({}, values);
    if (newValues.bitDepth !== undefined) {
        newValues.depth = newValues.bitDepth;
        delete newValues.bitDepth;
    }
    if (newValues.colourType !== undefined) {
        newValues.colorType = newValues.colourType;
        delete newValues.colourType;
    }
    check(img, newValues);
}
github Mogztter / asciidoctor-pdf.js / test / helper.js View on Github external
function computeImageDifferences (referenceBuffer, actualBuffer, diffFilename) {
  const referenceImage = PNG.sync.read(referenceBuffer)
  const actualImage = PNG.sync.read(actualBuffer)
  const { width, height } = referenceImage
  const diff = new PNG({ width, height })
  const numDiffPixels = pixelmatch(referenceImage.data, actualImage.data, diff.data, width, height, { threshold: 0.1 })
  fs.writeFileSync(diffFilename, PNG.sync.write(diff))
  return numDiffPixels
}
github AppraiseQA / appraise / spec / components / png-toolkit-spec.js View on Github external
beforeEach(() => {
			testPngBuffer = PNG.sync.write(initPic(100, 50));
		});
		it('returns the unmodified original buffer if the clip corresponds to the actual size', done => {
github TradeMe / tractor / packages / tractor-plugin-visual-regression / src / tractor / server / differ / check-diff.js View on Github external
return;
    }

    let error = new TractorError(`Visual Regression failed for ${filePath}`);
    if (imagesAreSameSize(baselinePNG, changesPNG)) {
        const diffPixelCount = pixelmatch(baselinePNG.data, changesPNG.data, diffPNG.data, width, height, { threshold: 0.1 });
        if (diffPixelCount === 0) {
            return;
        }

    } else {
        error = new TractorError(`New screenshot for ${filePath} is not the same size as baseline.`);    
    }

    diffPNGFile = diffPNGFile || new DiffPNGFile(diffsPath, fileStructure);
    await diffPNGFile.save(PNG.sync.write(diffPNG));
    throw error;
}
github oliver-moran / jimp / packages / type-png / src / index.js View on Github external
export default () => ({
  mime: { [MIME_TYPE]: ['png'] },

  constants: {
    MIME_PNG: MIME_TYPE,
    PNG_FILTER_AUTO,
    PNG_FILTER_NONE,
    PNG_FILTER_SUB,
    PNG_FILTER_UP,
    PNG_FILTER_AVERAGE,
    PNG_FILTER_PATH
  },

  hasAlpha: { [MIME_TYPE]: true },
  decoders: { [MIME_TYPE]: PNG.sync.read },
  encoders: {
    [MIME_TYPE]: data => {
      const png = new PNG({
        width: data.bitmap.width,
        height: data.bitmap.height
      });

      png.data = data.bitmap.data;

      return PNG.sync.write(png, {
        width: data.bitmap.width,
        height: data.bitmap.height,
        deflateLevel: data._deflateLevel,
        deflateStrategy: data._deflateStrategy,
        filterType: data._filterType,
        colorType:
github Klemen1337 / node-thermal-printer / lib / core.js View on Github external
async printImageBuffer(buffer) {
    try {
      var png = PNG.sync.read(buffer);
      let buff = this.printer.printImageBuffer(png.width, png.height, png.data);
      this.append(buff);
      return buff;
    } catch(error) {
      throw error;
    }
  }
github rumax / react-native-PixelsCatcher / src / runner / server / compareImages.js View on Github external
module.exports = (actual: any, expected: any, diffFile: any): number => {
  if (!actual || !fs.existsSync(actual)) {
    throw new Error(`Actual file is required, cannot get [${actual}] file`);
  }
  if (!expected || !fs.existsSync(expected)) {
    throw new Error(`Expected file is required, cannot get [${expected}] file`);
  }

  const imageActual = PNG.sync.read(fs.readFileSync(actual));
  const imageExpected = PNG.sync.read(fs.readFileSync(expected));

  const diff = new PNG({ width: imageExpected.width, height: imageExpected.height });

  const differentPixelsCount = pixelmatch(
    imageActual.data,
    imageExpected.data,
    diff.data,
    imageActual.width,
    imageActual.height,
    { threshold: 0.1 },
  );

  if (diffFile) {
    diff.pack().pipe(fs.createWriteStream(diffFile));
  }

pngjs

PNG encoder/decoder in pure JS, supporting any bit size & interlace, async & sync with full test suite.

MIT
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis