How to use exif-parser - 10 common examples

To help you get started, we’ve selected a few exif-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arackaf / booklist / node-src / app.js View on Github external
fs.readFile(pathToFileUploaded, (err, data) => {
                    if (err) {
                        console.log('ERROR', pathToFileUploaded, err);
                    }
                    let exifData = exif.create(data).parse(),
                        batchImage = null;

                    if (exifData && exifData.tags) {
                        switch (exifData.tags.Orientation) {
                            case 2:
                                batchImage = image.batch().flip('x'); // top-right - flip horizontal
                                break;
                            case 3:
                                batchImage = image.batch().rotate(180); // bottom-right - rotate 180
                                break;
                            case 4:
                                batchImage = image.batch().flip('y'); // bottom-left - flip vertically
                                break;
                            case 5:
                                batchImage = image.batch().rotate(90).flip('x'); // left-top - rotate 90 and flip horizontal
                                break;
github oliver-moran / jimp / index.js View on Github external
function exifRotate(image, buffer) {
    var exif = EXIFParser.create(buffer).parse();
    if (!exif || !exif.tags || !exif.tags.Orientation) return;
    switch (exif.tags.Orientation) {
        case 1: // Horizontal (normal)
            // do nothing
            break;
        case 2: // Mirror horizontal
            image.mirror(true, false);
            break;
        case 3: // Rotate 180
            image.rotate(180);
            break;
        case 4: // Mirror vertical
            image.mirror(false, true);
            break;
        case 5: // Mirror horizontal and rotate 270 CW
            image.mirror(true, false).rotate(270);
github oliver-moran / jimp / packages / core / src / utils / image-bitmap.js View on Github external
this._originalMime = mime.toLowerCase();

  try {
    const mime = this.getMIME();

    if (this.constructor.decoders[mime]) {
      this.bitmap = this.constructor.decoders[mime](data);
    } else {
      return throwError.call(this, 'Unsupported MIME type: ' + mime, cb);
    }
  } catch (error) {
    return cb.call(this, error, this);
  }

  try {
    this._exif = EXIFParser.create(data).parse();
    exifRotate(this); // EXIF data
  } catch (error) {
    /* meh */
  }

  cb.call(this, null, this);

  return this;
}
github furagu / easy-gd / lib / formats.js View on Github external
open: function openJpeg(imageData) {
            var image = gd.createFromJpegPtr(imageData)
            try {
                var exif = exifParser.create(imageData).parse()
            } catch (e) {
                // ignore exif parsing errors
            }
            if (!_.isEmpty(exif.tags)) image.exif = exif.tags
            return image
        },
        save: function saveJpeg(image, options) {
github jus / jus / lib / parsers / image.js View on Github external
image.title = path.basename(image.href).replace(patterns.image, '')

  // Look for cached image data
  if (cache && cache.images && cache.images[image.href]) {
    var cached = cache.images[image.href]
    // Dates that have been JSON stringified are weird. Use JSON.stringify to compare
    if (JSON.stringify(cached.stats.mtime) === JSON.stringify(image.stats.mtime)) {
      return callback(null, cached)
    }
  }

  image.dimensions = imageSize(image.processRelativePath)

  if (filepath.match(patterns.jpg)) {
    image.exif = exif.create(fs.readFileSync(image.processRelativePath)).parse()
  }

  getImageColors(image.processRelativePath, function(err, colors){
    if (err) return callback(err)
    image.colors = colors.map(color => color.hex())
    return callback(null, image)
  })

}
github how-to-firebase / fogo / app / functions / storage / uploads.onChange.js View on Github external
return file.download({ start: 0, end: 1024 }).then(([buffer]) => {
    let exif = {};
    try {
      exif = exifParser.create(buffer).parse();
    } catch (e) {
      console.log('exif parsing error', e);
    }
    return exif;
  });
}
github thumbsup / thumbsup / src / input / exif.js View on Github external
fs.readFile(filePath, function(err, contents) {
    if (err) return callback(new Error('Failed to read file ' + filePath));
    try {
      var result = exif.create(contents).parse();
    } catch (ex) {
      return callback(new Error('Failed to read EXIF from ' + filePath));
    }
    callback(null, {
      date: result.tags.DateTimeOriginal ? (result.tags.DateTimeOriginal * 1000) : null,
      orientation: result.tags.Orientation || null,
      caption: result.tags.ImageDescription
    });
  });
}
github picturama / picturama / src / background / MetaData.ts View on Github external
.then(buffer => {
            const parser = ExifParser.create(buffer) as any
            return parser.parse()
        })
}
github jus / jus / lib / files / image.js View on Github external
setExif () {
    if (!this.isJPEG()) return
    this.exif = exif.create(fs.readFileSync(this.path.processRelative)).parse()
  },
github gchq / CyberChef / src / core / operations / legacy / Image.js View on Github external
runExtractEXIF(input, args) {
        try {
            const parser = ExifParser.create(input);
            const result = parser.parse();

            let lines = [];
            for (let tagName in result.tags) {
                let value = result.tags[tagName];
                lines.push(`${tagName}: ${value}`);
            }

            const numTags = lines.length;
            lines.unshift(`Found ${numTags} tags.\n`);
            return lines.join("\n");
        } catch (err) {
            throw "Could not extract EXIF data from image: " + err;
        }
    },

exif-parser

A javascript library to extract Exif metadata from images, in node and in the browser.

MIT
Latest version published 7 years ago

Package Health Score

67 / 100
Full package analysis

Popular exif-parser functions