2018-05-28 00:27:11 +02:00
|
|
|
/**
|
|
|
|
* @author tlwr [toby@toby.codes]
|
|
|
|
* @copyright Crown Copyright 2017
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import { removeEXIF } from "../vendor/remove-exif.mjs";
|
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
import OperationError from "../errors/OperationError.mjs";
|
2018-05-28 00:27:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove EXIF operation
|
|
|
|
*/
|
|
|
|
class RemoveEXIF extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* RemoveEXIF constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "Remove EXIF";
|
|
|
|
this.module = "Image";
|
2018-05-29 00:42:43 +02:00
|
|
|
this.description = [
|
|
|
|
"Removes EXIF data from a JPEG image.",
|
|
|
|
"<br><br>",
|
|
|
|
"EXIF data embedded in 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";
|
2019-07-29 18:09:46 +02:00
|
|
|
this.inputType = "ArrayBuffer";
|
2018-05-28 00:27:11 +02:00
|
|
|
this.outputType = "byteArray";
|
|
|
|
this.args = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-29 18:09:46 +02:00
|
|
|
* @param {ArrayBuffer} input
|
2018-05-28 00:27:11 +02:00
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {byteArray}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
2019-07-29 18:09:46 +02:00
|
|
|
input = new Uint8Array(input);
|
2018-05-28 00:27:11 +02:00
|
|
|
// Do nothing if input is empty
|
|
|
|
if (input.length === 0) return input;
|
|
|
|
|
|
|
|
try {
|
|
|
|
return removeEXIF(input);
|
|
|
|
} catch (err) {
|
|
|
|
// Simply return input if no EXIF data is found
|
|
|
|
if (err === "Exif not found.") return input;
|
|
|
|
throw new OperationError(`Could not remove EXIF data from image: ${err}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default RemoveEXIF;
|