mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Add remove EXIF operation
This commit is contained in:
parent
57dcd961d5
commit
6741ba0783
5 changed files with 90 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import * as ExifParser from "exif-parser";
|
||||
import * as Piexifjs from "piexifjs";
|
||||
import Utils from "../Utils.js";
|
||||
import FileType from "./FileType.js";
|
||||
|
||||
|
@ -43,6 +44,31 @@ const Image = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove EXIF operation.
|
||||
*
|
||||
* Removes EXIF data from a byteArray, representing a JPG.
|
||||
*
|
||||
* @author David Moodie [davidmoodie12@gmail.com]
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
removeEXIF(input, args) {
|
||||
try {
|
||||
// Piexifjs seems to work best with base64 input
|
||||
const base64 = "data:image/jpeg;base64," + Utils.toBase64(input);
|
||||
const newImageB64 = Piexifjs.remove(base64);
|
||||
|
||||
// Convert the base64 back to byteArray
|
||||
const newImage = Utils.fromBase64(newImageB64.split(",")[1], null, "byteArray");
|
||||
return newImage;
|
||||
} catch (err) {
|
||||
// Simply return input if no EXIF data is found
|
||||
if (err == "Exif not found.") return input;
|
||||
throw "Could not remove EXIF data from image: " + err;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* @constant
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue