How to use pngjs - 10 common examples

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 DefinitelyTyped / DefinitelyTyped / types / pngjs / pngjs-tests.ts View on Github external
// closed
});
png.on('foo', () => {});

png.pack().adjustGamma();

png.parse('foo').adjustGamma();
png.parse(Buffer.from('foo')).adjustGamma();
png.parse('foo', (error, data) => {
    error.stack;
    data.adjustGamma();
}).adjustGamma();

PNG.adjustGamma(png);

PNG.bitblt(png, pngs[1]);
PNG.bitblt(png, pngs[1], 1, 1, 1, 1, 1, 1);
github DefinitelyTyped / DefinitelyTyped / types / pngjs / pngjs-tests.ts View on Github external
});
png.on('closed', () => {
    // closed
});
png.on('foo', () => {});

png.pack().adjustGamma();

png.parse('foo').adjustGamma();
png.parse(Buffer.from('foo')).adjustGamma();
png.parse('foo', (error, data) => {
    error.stack;
    data.adjustGamma();
}).adjustGamma();

PNG.adjustGamma(png);

PNG.bitblt(png, pngs[1]);
PNG.bitblt(png, pngs[1], 1, 1, 1, 1, 1, 1);
github jaanga / terrain-srtm30-plus / node-png-to-tms7 / r1 / png-to-tms7-r1-02.js View on Github external
fs.readFile( __dirname + '/test/test.png', function ( err, data ) {
								if ( err )  { // throw err;

									var tms = new PNG({
										width: xDelta,
										height: yDelta,
										filterType: -1
									});

									png.pack().pipe( fs.createWriteStream( __dirname + '/test/test.png' ) );
								}
								console.log( data );
							});
*/

							var tms = new PNG({
								width: xDelta,
								height: yDelta,
								filterType: -1
							});

							for ( var y = yStart; y < yFinish; y++ ) {
								tmsX = offX;
								for ( var x = xStart; x < xFinish; x++ ) {
										pngIdx = ( this.width * y + x ) * 4;
										tmsIdx = ( tms.width * tmsY + tmsX++ ) * 4;
										tms.data[ tmsIdx ] = this.data[ pngIdx ];
										tms.data[ tmsIdx + 1 ] = this.data[ pngIdx + 1 ];
										tms.data[ tmsIdx + 2 ] = this.data[ pngIdxc + 2 ];
										tms.data[ tmsIdx + 3 ] = 255;
								}
								tmsY++;
github taseenb / THREE.Highres / dist / THREE.Highres.es6.js View on Github external
convertArrayToPNG (array, size) {
    const image = new PNG({
      width: size.width,
      height: size.height
    })

    let i, wi
    for (let x = 0; x < size.width; x++) {
      for (let y = 0; y < size.height; y++) {
        // PNG indeces
        i = (size.width * y + x) << 2

        // Flip Y
        // const flipY = size.height - y

        // WebGL indeces
        wi = (size.width * (size.height - y) + x) << 2
github dumconstantin / generator-x / lib / Structure.js View on Github external
Structure.prototype.saveImage = function(pixmap) {
    var _this = this,
        pixel,
        location,
        pixels = pixmap.pixels,
        png = new PNG({
            width: pixmap.width,
            height: pixmap.height
        }),
        stream = fs.createWriteStream(this.currentGeneratedImage.filePath);

    // @TODO: The pixamp contains the end image width/height. Currently,
    // after generation, all images are parsed to read to real width and height.
    // Ideally we should save these in a JSON for future references to avoid IO.

    // @TODO: The ARGB to RGBA is processor intensive and blocking. This will require
    // a worker to handle pixmap saving.

    // Convert from ARGB to RGBA, we do this every 4 pixel values (channelCount)
    for(location = 0; location < pixels.length; location += pixmap.channelCount) {
        pixel = pixels[location];
        pixels[location]   = pixels[location + 1];
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 americanexpress / jest-image-snapshot / src / diff-snapshot.js View on Github external
composerParams.images.forEach((image, index) => {
        PNG.bitblt(
          image.imageData, compositeResultImage, 0, 0, image.imageWidth, image.imageHeight,
          composerParams.offsetX * index, composerParams.offsetY * index
        );
      });
      // Set filter type to Paeth to avoid expensive auto scanline filter detection
github apache / incubator-echarts / test / runTest / compareScreenshot.js View on Github external
return new Promise(resolve => {
        fs.createReadStream(path)
            .pipe(new PNG())
            .on('parsed', function () {
                resolve({
                    data: this.data,
                    width: this.width,
                    height: this.height
                });
            });
    });
}
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;
}

pngjs

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

MIT
Latest version published 2 years ago

Package Health Score

73 / 100
Full package analysis