How to use the pngjs.PNG 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 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 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 jaanga / terrain-srtm30-plus / node-srtm-to-tms7+ / r2 / srtm-to-tms7-r1-01.js View on Github external
.on('error', function() {
console.log('error', countPNG, file );

				var tms = new PNG({
					width: tmsWidth,
					height: tmsHeight,
					filterType: -1
				});
				this.data = tms.data;
//				this.pack().pipe( fs.createWriteStream( __dirname + '/test/test.png' )  );
				this.pack().pipe( fs.createWriteStream( __dirname + folderTMS + tileX + '/' + tileY + '.png' )  );
				countTMS++;
			})
github jaanga / terrain-srtm30-plus / node-png-to-tms7 / r2 / png-to-tms7-r2.js View on Github external
function processTMS( file, imageData, xWidth, xOffset, yOffset, xStart, xFinish, yStart, yFinish, tileX, tileY ) {
		fs.createReadStream( __dirname + folderTMS + file )
			.pipe( new PNG() )
			.on('error', function() {
				var tms = new PNG({
					width: xFinish - xStart,
					height: yFinish - yStart,
					filterType: -1
				});
				this.data = tms.data;
//				this.pack().pipe( fs.createWriteStream( __dirname + '/testa/test.png' )  );
				this.pack().pipe( fs.createWriteStream( __dirname + '/../../tms7/' + tileX + '/' + tileY + '.png' )  );
console.log('error', count, file );
				count++;
			})
			.on('parsed', function () {
				var pngIdx, tmsIdx;
				var tmsX, tmsY = yOffset;
				var pngWidth = xWidth;
github derrickoswald / CIMSpace / sprites / make-sdf.js View on Github external
function (file)
            {
                var name = file.match (/png\/(.*)\.png/)[1];
                fs.createReadStream (file).pipe (new PNG ({ filterType: 4 })).on('parsed',
                    function ()
                    {
                        console.log (name);
                        var bitmap = new Array (this.height * this.width)
                        for (var y = 0; y < this.height; y++)
                            for (var x = 0; x < this.width; x++)
                            {
                                var offset = this.width * y + x;
                                var idx = offset << 2;
                                bitmap[offset] = inside (this.data[idx + 3])
                            }

                        var png = new PNG ({width: this.width, height: this.height});
                        for (var y = 0; y < this.height; y++)
                            for (var x = 0; x < this.width; x++)
                            {
github AppraiseQA / appraise / src / components / png-toolkit.js View on Github external
self.clip = function (pngBufferData, requestedClip) {
		const result =  new PNG({width: requestedClip.width, height: requestedClip.height});
		return loadPng(pngBufferData)
			.then(sourcePng => {
				if (sourcePng.width === requestedClip.width && sourcePng.height === requestedClip.height && requestedClip.x === 0 && requestedClip.y === 0) {
					return pngBufferData;
				}
				sourcePng.bitblt(result, requestedClip.x, requestedClip.y, requestedClip.width, requestedClip.height, 0, 0);
				return PNG.sync.write(result);
			});
	};
	self.readPng = readPng;
github genify / toolkit2 / lib / adapter / sprite.js View on Github external
list.forEach(function(it,index){
            fs.createReadStream(it).pipe(
                new PNG()
            ).on('parsed',function(){
                callback(key,index,{
                    width:this.width,
                    height:this.height,
                    meta:{file:it,inst:this}
                });
            });
        });
    },this);
github microsoft / pxt / cli / gdb.ts View on Github external
let objects: pxt.Map = {}

    let byCategory: pxt.Map = {}
    let numByCategory: pxt.Map = {}
    let maxFree = 0

    const string_inline_ascii_vt = findAddr("pxt::string_inline_ascii_vt")
    const string_inline_utf8_vt = findAddr("pxt::string_inline_utf8_vt")
    const string_cons_vt = findAddr("pxt::string_cons_vt")
    const string_skiplist16_vt = findAddr("pxt::string_skiplist16_vt")

    const PNG: any = require("pngjs").PNG;
    const visWidth = 256
    const visHeight = 256
    const heapVis = new PNG({ width: visWidth, height: visHeight })
    const visData: Uint8Array = heapVis.data

    for (let i = 0; i < visWidth * visHeight * 4; ++i)
        visData[i] = 0xff

    /*
    struct VTable {
        uint16_t numbytes;
        ValType objectType;
        uint8_t magic;
        PVoid *ifaceTable;
        BuiltInType classNo;
    };
    */
    for (let gcHeap = read32(findAddr("pxt::firstBlock")); gcHeap; gcHeap = read32(gcHeap)) {
        let heapSize = read32(gcHeap + 4)

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