2018-05-28 00:27:11 +02:00
|
|
|
/**
|
|
|
|
* @author tlwr [toby@toby.codes]
|
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
import ExifParser from "exif-parser";
|
|
|
|
import Operation from "../Operation";
|
|
|
|
import OperationError from "../errors/OperationError";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Extract EXIF operation
|
|
|
|
*/
|
|
|
|
class ExtractEXIF extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ExtractEXIF constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Extract EXIF";
|
|
|
|
this.module = "Image";
|
2018-05-29 00:42:43 +02:00
|
|
|
this.description = [
|
|
|
|
"Extracts EXIF data from an image.",
|
|
|
|
"<br><br>",
|
|
|
|
"EXIF data is metadata embedded in images (JPEG, JPG, TIFF) and audio files.",
|
|
|
|
"<br><br>",
|
|
|
|
"EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
|
|
|
|
].join("\n");
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Exif";
|
2018-05-28 00:27:11 +02:00
|
|
|
this.inputType = "ArrayBuffer";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {ArrayBuffer} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
try {
|
|
|
|
const parser = ExifParser.create(input);
|
|
|
|
const result = parser.parse();
|
|
|
|
|
|
|
|
const lines = [];
|
|
|
|
for (const tagName in result.tags) {
|
|
|
|
const 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 new OperationError(`Could not extract EXIF data from image: ${err}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExtractEXIF;
|