modify-exif

0.0.1 • Public • Published

modify-exif

npm version Build Status Coverage Status

Modify Exif data of a JPEG and create a new Buffer

const {readFile} = require('fs').promises;
const getExif = require('get-exif');
const modifyExif = require('modify-exif');
 
(async () => {
  // The original photo is taken at 2017:11:19 08:47:19
  const originalFile = await readFile('example.jpg');
  getExif(originalFile).Exif; //=> '2017:11:19 08:47:19'
 
  const newFile = modifyExif(await readFile('example.jpg'), data => {
    // 36867: tag ID of `DateTimeOriginal` tag
    data.Exif['36867'] = '2018:06:15 12:00:00'
  });
 
  getExif(newFile).Exif; //=> '2018:06:15 12:00:00'
})();

Installation

Use npm.

npm install modify-exif

API

const modifyExif = require('modify-exif');

modifyExif(buffer, modifierFn [, option])

buffer: Buffer (data of a JPEG file)
modifierFn: Function (a function to transform a passed Object inside it)
option: Object Return: Object

It reads Exif data from a Buffer using Piexifjs, pass it to the modifier function and return a new Buffer of the image with updated Exif data.

Note that the original Buffer is not modified.

const newBuffer = modifyExif(imageBuffer, data => {
  data; /*=> {
    '0th': { ... },
    '1st': { ... },
    Exif: { ... },
    GPS: { ... }
    Interop: { ... },
    thumbnail: ' ... '
  } */
 
  // 305: tag ID of `Software` tag
  data['0th'][305] = 'My Camera'
});

option.keepDateTime

Type: boolean
Default: false

By default DataTime tag (file change date and time) of the 0th IFD is updated to the current date and time.

true disables this behavior.

License

ISC License © 2018 Shinnosuke Watanabe

Dependents (1)

Package Sidebar

Install

npm i modify-exif

Weekly Downloads

44

Version

0.0.1

License

ISC

Unpacked Size

5.92 kB

Total Files

4

Last publish

Collaborators

  • shinnn