1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

sync sample node with main sample

reduce exif error messages so false-positives don't keep getting reported
This commit is contained in:
dceejay 2015-01-12 19:14:04 +00:00
parent ac0aa40e24
commit fb7ccc7736
3 changed files with 26 additions and 25 deletions

View File

@ -31,6 +31,8 @@ module.exports = function(RED) {
// Store local copies of the node configuration (as defined in the .html) // Store local copies of the node configuration (as defined in the .html)
this.topic = n.topic; this.topic = n.topic;
// copy "this" object in case we need it in context of callbacks of other functions.
var node = this; var node = this;
// Do whatever you need to do in here - declare callbacks etc // Do whatever you need to do in here - declare callbacks etc
@ -43,16 +45,16 @@ module.exports = function(RED) {
// send out the message to the rest of the workspace. // send out the message to the rest of the workspace.
// ... this message will get sent at startup so you may not see it in a debug node. // ... this message will get sent at startup so you may not see it in a debug node.
node.send(msg); this.send(msg);
// respond to inputs.... // respond to inputs....
node.on('input', function (msg) { this.on('input', function (msg) {
node.warn("I saw a payload: "+msg.payload); node.warn("I saw a payload: "+msg.payload);
// in this example just send it straight on... should process it here really // in this example just send it straight on... should process it here really
node.send(msg); node.send(msg);
}); });
node.on("close", function() { this.on("close", function() {
// Called when the node is shutdown - eg on redeploy. // Called when the node is shutdown - eg on redeploy.
// Allows ports to be closed, connections dropped etc. // Allows ports to be closed, connections dropped etc.
// eg: node.client.disconnect(); // eg: node.client.disconnect();

View File

@ -17,13 +17,13 @@
module.exports = function(RED) { module.exports = function(RED) {
"use strict"; "use strict";
var ExifImage = require('exif').ExifImage; var ExifImage = require('exif').ExifImage;
function convertDegreesMinutesSecondsToDecimals(degrees, minutes, seconds) { function convertDegreesMinutesSecondsToDecimals(degrees, minutes, seconds) {
var result; var result;
result = degrees + (minutes / 60) + (seconds / 3600); result = degrees + (minutes / 60) + (seconds / 3600);
return result; return result;
} }
/*** /***
* Extracts GPS location information from Exif data. If enough information is * Extracts GPS location information from Exif data. If enough information is
* provided, convert the Exif data into a pair of single floating point number * provided, convert the Exif data into a pair of single floating point number
@ -46,7 +46,7 @@ module.exports = function(RED) {
if(gpsData.GPSLongitude.length === 3) { // OK to convert longitude if(gpsData.GPSLongitude.length === 3) { // OK to convert longitude
var latitude = convertDegreesMinutesSecondsToDecimals(gpsData.GPSLatitude[0], gpsData.GPSLatitude[1], gpsData.GPSLatitude[2]); var latitude = convertDegreesMinutesSecondsToDecimals(gpsData.GPSLatitude[0], gpsData.GPSLatitude[1], gpsData.GPSLatitude[2]);
latitude = Math.round(latitude * 100000)/100000; latitude = Math.round(latitude * 100000)/100000;
// (N)orth means positive latitude // (N)orth means positive latitude
// (S)outh means negative latitude // (S)outh means negative latitude
// (E)ast means positive longitude // (E)ast means positive longitude
@ -54,10 +54,10 @@ module.exports = function(RED) {
if(gpsData.GPSLatitudeRef.toString() === 'S' || gpsData.GPSLatitudeRef.toString() === 's') { if(gpsData.GPSLatitudeRef.toString() === 'S' || gpsData.GPSLatitudeRef.toString() === 's') {
latitude = latitude * -1; latitude = latitude * -1;
} }
var longitude = convertDegreesMinutesSecondsToDecimals(gpsData.GPSLongitude[0], gpsData.GPSLongitude[1], gpsData.GPSLongitude[2]); var longitude = convertDegreesMinutesSecondsToDecimals(gpsData.GPSLongitude[0], gpsData.GPSLongitude[1], gpsData.GPSLongitude[2]);
longitude = Math.round(longitude * 100000)/100000; longitude = Math.round(longitude * 100000)/100000;
if(gpsData.GPSLongitudeRef.toString() === 'W' || gpsData.GPSLongitudeRef.toString() === 'w') { if(gpsData.GPSLongitudeRef.toString() === 'W' || gpsData.GPSLongitudeRef.toString() === 'w') {
longitude = longitude * -1; longitude = longitude * -1;
} }
@ -86,25 +86,24 @@ module.exports = function(RED) {
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
try { try {
if (msg.payload) {
if(msg.payload) { if (Buffer.isBuffer(msg.payload)) {
var isBuffer = Buffer.isBuffer(msg.payload);
if(isBuffer === true) {
new ExifImage({ image : msg.payload }, function (error, exifData) { new ExifImage({ image : msg.payload }, function (error, exifData) {
if (error) { if (error) {
node.error('Failed to extract Exif data from image.'); //node.error('Failed to extract Exif data from image.');
node.log('Failed to extract Exif data from image. '+ error); //node.log('Failed to extract Exif data from image. '+ error);
node.log(error);
} else {
//msg.payload remains the same buffer
if(exifData) {
msg.exif = exifData;
addMsgLocationDataFromExifGPSData(msg);
} else { } else {
//msg.payload remains the same buffer node.warn("The incoming buffer did not contain Exif data, nothing to do. ");
if(exifData) {
msg.exif = exifData;
addMsgLocationDataFromExifGPSData(msg);
} else {
node.warn("The incoming buffer did not contain Exif data, nothing to do. ");
}
} }
node.send(msg); }
}); node.send(msg);
});
} else { } else {
node.error("Invalid payload received, the Exif node cannot proceed, no messages sent."); node.error("Invalid payload received, the Exif node cannot proceed, no messages sent.");
return; return;

View File

@ -1,6 +1,6 @@
{ {
"name" : "node-red-node-exif", "name" : "node-red-node-exif",
"version" : "0.0.1", "version" : "0.0.2",
"description" : "A Node-RED node that extracts Exif information from JPEG image buffers.", "description" : "A Node-RED node that extracts Exif information from JPEG image buffers.",
"dependencies" : { "dependencies" : {
"exif": "0.4.0" "exif": "0.4.0"