News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

node.js & dist-exiftool

Started by sorgeas, February 14, 2021, 08:23:10 AM

Previous topic - Next topic

sorgeas

Hello,

I'm having trouble running exiftool from an Azure function, using node.js & dist-exiftool.

Here is the code I'm running:

const
    fs = require('fs'),
    exec = require('child_process').execFile,
    exiftool = require('dist-exiftool'),
    util = require('util'),
    execAsync = util.promisify(exec);

module.exports = async function (context, req) {
    context.log('HTTP trigger function processed a request.');

    const folder = "c:\\home\\data\\";
    const input = folder + "testFile.jpg";
    const exifToolParams = "-GPSLongitudeRef=W -GPSLongitude=0.006572 -GPSLatitudeRef=N -GPSLatitude=51.483822";

    try {
        // call exiftool
        context.log("Running: exiftool " + exifToolParams + " ", input);
        const { stdout, stderr } = await execAsync(exiftool, [exifToolParams, input]);
        context.log('stdout:', stdout);
        context.log('stderr:', stderr);

        context.res = {
            // status: 200, /* Defaults to 200 */
            body: "ok"
        };
    }
    catch(e) {
        context.log.error(e);

        context.res = {
            status: 500,
            body: e
        };
    }
}


When debugging the above code, I get the following error:

Error: Command failed: C:\source\repos\myazurefunction\node_modules\exiftool.exe\vendor\exiftool.exe -GPSLongitudeRef=W -GPSLongitude=0.006572 -GPSLatitudeRef=N -GPSLatitude=51.483822 c:\home\data\testFile.jpg
Warning: Can't convert GPS:GPSLongitudeRef (not in PrintConv)
Nothing to do.
    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:198:13)
    at maybeClose (internal/child_process.js:982:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   'C:\\source\\repos\\myazurefunction\\node_modules\\exiftool.exe\\vendor\\exiftool.exe -GPSLongitudeRef=W -GPSLongitude=0.006572 -GPSLatitudeRef=N -GPSLatitude=51.483822 c:\\home\\data\\testFile.jpg',
  stdout: '',
  stderr:
   'Warning: Can\'t convert GPS:GPSLongitudeRef (not in PrintConv)\r\nNothing to do.\r\n' }


The weird thing is that I get no error when executing the exact same command from my Windows command prompt, using the exiftool command line (v10.5.3.0) from the npm package...

Any help would be appreciated :)

StarGeek

I have no knowledge of nodejs, but one problem I've seen a lot when running exiftool as an external program is that the arguments to exiftool get passed as one single argument rather than separate arguments.

Try running the command with only one argument.  For example, run the command with just -GPSLatitudeRef=N and see if that works. Then build it up bit by bit.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sorgeas

Actually I know it works pretty well with one single parameter, for instance "-all=".

Indeed combining several parameters causes inconsistent behaviours... I was thinking the error message I've posted could help understanding what is going wrong

StarGeek

The problem with the not in PrintConv error is that it doesn't narrow much down.  It just means that GPSLatitudeRef is being assigned something other than N/S or a number.

What's the output when you assign just the GPS coordinates, -GPSLongitude=0.006572 -GPSLatitude=51.483822

You may have to use the -v (verbose) option and try and capture that output to see what the actual assignments are.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

sorgeas

Unfortunately even the -v (or -verbose) option is not recognized: I end up with the message  Warning: Tag 'verbose' is not defined.
Of course running the same from a command prompt works perfectly...

If I don't add the -v option but only keep -GPSLongitude=0.006572 -GPSLatitude=51.483822, the command doesn't fail but there is no geodata added to the test file.

sorgeas

I finally found the issue in the way I was passing the parameters from my node.js function... the good approach being:

await execAsync(exiftool, ["-v", "-GPSLongitudeRef=W", "-GPSLongitude=0.006572", "-GPSLatitudeRef=N", "-GPSLatitude=51.483822", input])


Instead of:

await execAsync(exiftool, ["-v -GPSLongitudeRef=W -GPSLongitude=0.006572 -GPSLatitudeRef=N -GPSLatitude=51.483822", input])


Thank you very much for your help!