CyberChef/src/core/operations/Image.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-04-29 21:44:39 +02:00
import * as ExifParser from "exif-parser";
import Utils from "../Utils.js";
/**
* Image operations.
*
* @author tlwr [toby@toby.codes]
* @copyright Crown Copyright 2017
* @license Apache-2.0
*
* @namespace
*/
const Image = {
2017-05-13 17:08:14 +02:00
/**
* Extract EXIF operation.
*
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
*
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
2017-04-29 21:44:39 +02:00
runEXIF(input, args) {
try {
2017-05-08 18:49:13 +02:00
const bytes = Uint8Array.from(input);
const parser = ExifParser.create(bytes.buffer);
const result = parser.parse();
2017-04-29 21:44:39 +02:00
let lines = [];
for (let tagName in result.tags) {
let value = result.tags[tagName];
lines.push(`${tagName}: ${value}`);
}
2017-05-08 18:49:13 +02:00
const numTags = lines.length;
2017-04-29 21:44:39 +02:00
lines.unshift(`Found ${numTags} tags.\n`);
return lines.join("\n");
} catch (err) {
throw "Could not extract EXIF data from image: " + err;
2017-04-29 21:44:39 +02:00
}
},
2017-05-13 17:08:14 +02:00
2017-04-29 21:44:39 +02:00
};
export default Image;