# Write Exif/Metadata to file

**URL:** <https://discourse.nodered.org/t/write-exif-metadata-to-file/49699>\
**Category:** General\
**Created:** [13 August 2021 20:46 UTC](https://discourse.nodered.org/t/write-exif-metadata-to-file/49699 "2021-08-13T20:46:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nbra](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@Nbra](https://discourse.nodered.org/u/Nbra)\
**Post date:** [13 August 2021 20:46 UTC](https://discourse.nodered.org/t/write-exif-metadata-to-file/49699/1 "2021-08-13T20:46:31Z")

</div>

Hi,

Has anyone a good solution for _writing_ geotag data to a image file via Node Red? I see there is many good solutions for reading exif data.

Im extracting .jpeg images from a RTSP stream using ffmpeg in a exec node, but I would also like to add metada and geotags to those images after they are created.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 August 2021 10:55 UTC](https://discourse.nodered.org/t/write-exif-metadata-to-file/49699/2 "2021-08-15T10:55:37Z")

</div>

> [@Nbra](#):
>
> Im extracting .jpeg images from a RTSP stream using ffmpeg in a exec node, but I would also like to add metada and geotags to those images after they are created.

If you are using latest node-red, you could import [piexifjs](https://github.com/hMatoba/piexifjs)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/1/919b15d4e4ca7a875be159c7adb1bab0cafe0271.png)

#### Here is a demo that adds a date taken, camera model and GPS coords...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/8/8838829967f71d5fd8638f223a3bac842e2c6081.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/4/e4823aeacce126a6b4c0855a19aa172a9a7face7.jpeg)

#### The flow...

```auto
[{"id":"5415f454ebdea80d","type":"function","z":"62a0e5a5.fc59bc","name":"","func":"\n/*\nvar filename1 = \"c:/temp/pic1.jpg\";\nvar jpeg = fs.readFileSync(filename1);\nvar data = jpeg.toString(\"binary\");\n*/\n\nvar jpegData = msg.payload;\nvar exifOrig\ntry {\n exifOrig = piexif.load(jpegData)\n} catch (error) {\n \n};\n\n//debugger\nvar zeroth = {};\nvar exif = {};\nvar gps = {};\nzeroth[piexif.ImageIFD.Make] = \"RPi\";\nzeroth[piexif.ImageIFD.Model] = \"3b\";\nzeroth[piexif.ImageIFD.Software] = \"node-red\";\n\nexif[piexif.ExifIFD.DateTimeOriginal] = \"2010:10:10 10:10:10\";\nexif[piexif.ExifIFD.ExifVersion] = [1]\nexif[piexif.ExifIFD.LensMake] = \"LensMake\";\nexif[piexif.ExifIFD.Sharpness] = 777;\nexif[piexif.ExifIFD.LensSpecification] = [[1, 1], [1, 1], [1, 1], [1, 1]];\n\ngps[piexif.GPSIFD.GPSVersionID] = [7, 7, 7, 7];\ngps[piexif.GPSIFD.GPSDateStamp] = \"1999:99:99 99:99:99\";\n\nvar lat = 54.998993228419344 ;\nvar lng = -1.4174938201904297;\ngps[piexif.GPSIFD.GPSLatitudeRef] = lat < 0 ? 'S' : 'N';\ngps[piexif.GPSIFD.GPSLatitude] = piexif.GPSHelper.degToDmsRational(lat);\ngps[piexif.GPSIFD.GPSLongitudeRef] = lng < 0 ? 'W' : 'E';\ngps[piexif.GPSIFD.GPSLongitude] = piexif.GPSHelper.degToDmsRational(lng);\n\nvar exifObj = Object.assign({}, exifOrig);\nexifObj[\"0th\"] = Object.assign({}, exifOrig[\"0th\"], zeroth )\nexifObj[\"Exif\"] = Object.assign({}, exifOrig[\"Exif\"], exif )\nexifObj[\"GPS\"] = Object.assign({}, exifOrig[\"GPS\"], gps )\n\n//var exifObj = { \"0th\": zeroth, \"Exif\": exif, \"GPS\": gps };\n\nvar exifStr = piexif.dump(exifObj);\n\nvar jpegDataUpdated = piexif.insert(exifStr, jpegData);\n\nmsg.payload = Buffer.from(jpegDataUpdated, \"binary\");\n\nreturn [msg, { payload: exifOrig }, { payload: exifObj }];","outputs":3,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"piexif","module":"piexifjs"}],"x":780,"y":600,"wires":[["3dd297d64de8d2d2"],["e61fe407cd2de8a1"],["5c38fe17cc056387"]]},{"id":"8e75f2cc120f0e4b","type":"inject","z":"62a0e5a5.fc59bc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":420,"y":600,"wires":[["2415a6d7db4da43d"]]},{"id":"84fa15419e139892","type":"image viewer","z":"62a0e5a5.fc59bc","name":"","width":160,"data":"payload","dataType":"msg","active":true,"x":1190,"y":580,"wires":[[]]},{"id":"3dd297d64de8d2d2","type":"file","z":"62a0e5a5.fc59bc","name":"","filename":"c:/temp/pic_exif.jpg","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":1010,"y":580,"wires":[["84fa15419e139892"]]},{"id":"2415a6d7db4da43d","type":"file in","z":"62a0e5a5.fc59bc","name":"","filename":"c:/temp/pic1.jpg","format":"utf8","chunk":false,"sendError":false,"encoding":"binary","allProps":false,"x":600,"y":600,"wires":[["5415f454ebdea80d"]]},{"id":"e61fe407cd2de8a1","type":"debug","z":"62a0e5a5.fc59bc","name":"orig exif","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":620,"wires":[]},{"id":"5c38fe17cc056387","type":"debug","z":"62a0e5a5.fc59bc","name":"new exif","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":660,"wires":[]}]

```

Checkout the function code ↑ in the flow (use CTRL+I to import the flow)

---

<div class="post-metadata">

**Author:** ![Nbra](https://avatars.discourse-cdn.com/v4/letter/n/dec6dc/32.png) [@Nbra](https://discourse.nodered.org/u/Nbra)\
**Post date:** [18 August 2021 06:51 UTC](https://discourse.nodered.org/t/write-exif-metadata-to-file/49699/3 "2021-08-18T06:51:04Z")

</div>

This was simply spot on! Thanks for the help.

Was skratching my head for a while, but I had to remove piexifjs from the function node I imported and re-instate it, first it threw me this "_TypeError: The argument 'path' must be a string or Uint8Array without null bytes"._

Works like a charm now.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 September 2021 06:52 UTC](https://discourse.nodered.org/t/write-exif-metadata-to-file/49699/4 "2021-09-01T06:52:04Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
