浏览代码

Add remove EXIF operation

David Moodie 8 年之前
父节点
当前提交
6741ba0783
共有 5 个文件被更改,包括 54 次插入0 次删除
  1. 1 0
      package.json
  2. 1 0
      src/core/config/Categories.js
  3. 13 0
      src/core/config/OperationConfig.js
  4. 26 0
      src/core/operations/Image.js
  5. 13 0
      test/tests/operations/Image.js

+ 1 - 0
package.json

@@ -80,6 +80,7 @@
     "lodash": "^4.17.4",
     "lodash": "^4.17.4",
     "moment": "^2.17.1",
     "moment": "^2.17.1",
     "moment-timezone": "^0.5.11",
     "moment-timezone": "^0.5.11",
+    "piexifjs": "^1.0.3",
     "sladex-blowfish": "^0.8.1",
     "sladex-blowfish": "^0.8.1",
     "sortablejs": "^1.5.1",
     "sortablejs": "^1.5.1",
     "split.js": "^1.2.0",
     "split.js": "^1.2.0",

+ 1 - 0
src/core/config/Categories.js

@@ -210,6 +210,7 @@ const Categories = [
             "XPath expression",
             "XPath expression",
             "CSS selector",
             "CSS selector",
             "Extract EXIF",
             "Extract EXIF",
+            "Remove EXIF",
         ]
         ]
     },
     },
     {
     {

+ 13 - 0
src/core/config/OperationConfig.js

@@ -3388,6 +3388,19 @@ const OperationConfig = {
             }
             }
         ]
         ]
     },
     },
+    "Remove EXIF": {
+        description: [
+            "Removes 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"),
+        run: Image.removeEXIF,
+        inputType: "byteArray",
+        outputType: "byteArray",
+        args: [],
+    },
 };
 };
 
 
 export default OperationConfig;
 export default OperationConfig;

+ 26 - 0
src/core/operations/Image.js

@@ -1,4 +1,5 @@
 import * as ExifParser from "exif-parser";
 import * as ExifParser from "exif-parser";
+import * as Piexifjs from "piexifjs";
 import Utils from "../Utils.js";
 import Utils from "../Utils.js";
 import FileType from "./FileType.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
      * @constant

文件差异内容过多而无法显示
+ 13 - 0
test/tests/operations/Image.js


部分文件因为文件数量过多而无法显示