Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

read/write Windows image tags (keywords)

Windows image tags in properties Windows image tags in status bar

.

How can I read/write these tags from a file on Windows?

I'm trying to acheive it in javascript and node.js but failed to find information in any language at all so I'm looking for any clues.

.

The word tags (sometimes called keywords) seem to be unfortunately chosen, as it appears to be normally describing any metadata of a file, such as EXIF. Yet in windows you can save such descriptive-tags as one of the file tags. To start with - any idea on how are they really called?

I'm aware you can modify them using various programs, eg. in Adobe Bridge they're called keywords of a file.

.

Note: I do realise it's not the best solution of storing file tags. I really just need to work with these, since the image library I'm working with is using them heavily.

[Edit.1]

@Ben Fortune: Thanks for the clue! Still, Exif-parser gives a way to read these tags, however does not allow for writing.

like image 225
Voy Avatar asked Oct 20 '25 14:10

Voy


1 Answers

And the answers are:

  1. These Windows tags are really called EXIF XPKeywords. See the full list here
  2. Parsing a file using Exif Parser is good for reading, however they come back as decimal ASCII code. Using

    String.fromCharCode()
    

    and looping through the returned integers I managed to get the tags as strings.

  3. However, for reading AND writing I ended up going with the exiftool. Therefore, I'm using

    function run_cmd(cmd, args, callBack ) {
        var spawn = require('child_process').spawn;
        var child = spawn(cmd, args);
        var resp = "";
    
        child.stdout.on('data', function (buffer) { resp += buffer.toString() });
        child.stdout.on('end', function() { callBack (resp) });
    } // ()
    

    to execute the exiftool as a shell command (More on spawning shell command)

.

For reading I'm passing

    run_cmd('exiftool', ['-XPKeywords', myFilepath])

to read the XPKeywords tag and

    theShellResult.match(/:(.*)/)

to filter out only the keywords (Nicely explained here).

.

For writing (appending) new XPKeywords I'm simply changing the args to:

    var writeArg = "-XPKeywords<$XPKeywords " + myNewKeywords
    run_cmd('exiftool', [writeArg, myFilepath])

.

I found a way around it but I'd be calm knowing it is not executed through a shell command. Therefore, the question remains open - Can you suggest a good the interface for reading and writing EXIF tags in node.js?

like image 138
Voy Avatar answered Oct 22 '25 05:10

Voy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!