Esempio n. 1
0
 return function(cb, eb) {
     try {
         var fs = require("fs"),
             PNG = require("pngparse");
         return PNG.parseFile(fp, function(err, id) {
             if (err) return eb(err);
             var x,
                 y,
                 idx,
                 isWhite,
                 count = 0;
             for (x = 0; x < id.width; x++) {
                 for (y = 0; y < id.height; y++) {
                     isWhite = id.getPixel(x, y) == 0xFFFFFFCC;
                     if (!isWhite) {
                         count = count + 1;
                     }
                 }
             }
             return cb({
                 count: count,
                 percent: 100 * count / (id.width * id.height)
             });
         });
     }
     catch (e) {
         return eb(e);
     }
 };
Esempio n. 2
0
function img2txt(file, opt, cb){
  if (typeof opt === 'function') {
    cb = opt
    opt = null
  }
  opt = _.extend({
    fontSize: 12, // minimum on chrome
    nocolor: false,
    nohtml: false
  }, opt)

  var buf
  try {
    buf = fs.readFileSync(file)
  } catch(err) {
    return cb(err)
  }

  pngparse.parseFile(file, function(err, img){
    if (err) return cb(err)
    render(img, opt, function(err, ret){
      cb(err, ret)
    })
  })
}
Esempio n. 3
0
function pngtolcd(filename, cb) {
  pngparse.parseFile(filename, function(err, img) {
    if (err) {
      return cb(err);
    }     
    var buffer = tolcd(img);
    cb(err, buffer)
  });
}
Esempio n. 4
0
test('should return expected image object', function(t) {
  pngparse.parseFile(__dirname + '/png/test0.png', function(err, image) {
    var testDither = floydSteinberg(image);
    t.equal(typeof testDither.width, 'number');
    t.equal(typeof testDither.height, 'number');
    t.equal(typeof testDither.data, 'object');

    t.end();
  });
});
Esempio n. 5
0
	function getColorOfImageFirstPixel(path, callback) {
		pngparse.parseFile(path, function(err, data) {
			if (err) {
				throw err;
			}

			var hex = data.getPixel(0, 0);
			hex = hex >> 8;
			callback(hex);
		});
	}
Esempio n. 6
0
function displayPNG(filename, onFinish){
			pngparse.parseFile(path.join(imgDir, filename), function(err, data) {
 	 	    if(err)
    		  throw err
  		console.log(data); 
  		console.log('writing to device');
      //append 1 black row
  		var imgBuffer = Buffer.concat([data.data, blackBuffer]);
   		myLedStripe.animate(imgBuffer,'10m', onFinish);
	});
	return;
}
Esempio n. 7
0
test('should return monochrome pixels', function(t) {
  pngparse.parseFile(__dirname + '/png/test1.png', function(err, image) {
    var testDither = floydSteinberg(image);
    var imageData = testDither.data;
    var imageDataLen = testDither.data.length;

    // test first pixel to see if it's grey/black/white
    var redPixel = imageData[0];
    t.equal(imageData[1], redPixel);
    t.equal(imageData[2], redPixel);

    t.end();
  });
});
Esempio n. 8
0
/*
 * Same Image
 * Check if images are the same with simple/fast pixle by pixle comparison
 */
function sameImage(imageReferenced, imageToCompare, callback) {
    pngparse.parseFile(imageReferenced, function(err, imageA) {
        if (err) {
            console.log('imageDiff - Error parsing given imageReferenced! ', err);
            return callback({
                failure: true
            });
        }
        pngparse.parseFile(imageToCompare, function(err, imageB) {
            if (err) {
                console.log('imageDiff - Error parsing given imageToCompare! ', err);
                return callback({
                    failure: true
                });
            }

            // Simple size check
            if (imageA.data.length !== imageB.data.length) {
                return callback({
                    same: false,
                    percentage: null
                });
            }

            // Loop over pixels, but skip 4th alpha propery as these images should not be transparent
            var damagedPxCnt = 0;
            for (var i = 0, len = imageA.data.length; i < len; i += 4) {
                if (imageA.data[i]     !== imageB.data[i] ||
                    imageA.data[i + 1] !== imageB.data[i + 1] ||
                    imageA.data[i + 2] !== imageB.data[i + 2]) {
                        damagedPxCnt++;
                }
            }
            if (damagedPxCnt > 0) {
                callback({
                    same: false,
                    percentage: damagedPxCnt/imageB.data.length * 100
                });
            } else {
                callback({
                    same: true,
                    percentage: damagedPxCnt/imageB.data.length * 100
                });
            }
        });
    });
}
Esempio n. 9
0
function get_map_image_borders (src) {
    /*
    This function examines the map PNG and locates the map borders. These will
    be used for cropping the image to only have the map and not include the
    white area, legend, etc.
    */
    var deferred = Q.defer();
    console.log('Find the map square!', src);
    pngparse.parseFile(src, function(err, data) {
        if (err) {
            return deferred.reject(err);
        }
        var png_data = data;
        var cut_lines = {
            n: test_columns(png_data, false),
            s: test_columns(png_data, true),
            e: test_rows(png_data, true),
            w: test_rows(png_data, false)
        };
        deferred.resolve({src: src, cut: cut_lines});
    });
    return deferred.promise;
}
Esempio n. 10
0
 return function (callback) {
     pngparse.parseFile(filename, callback);
 }