RemoveEXIF.mjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * @author tlwr [toby@toby.codes]
  3. * @copyright Crown Copyright 2017
  4. * @license Apache-2.0
  5. */
  6. import { removeEXIF } from "../vendor/remove-exif";
  7. import Operation from "../Operation";
  8. import OperationError from "../errors/OperationError";
  9. /**
  10. * Remove EXIF operation
  11. */
  12. class RemoveEXIF extends Operation {
  13. /**
  14. * RemoveEXIF constructor
  15. */
  16. constructor() {
  17. super();
  18. this.name = "Remove EXIF";
  19. this.module = "Image";
  20. this.description = "Removes EXIF data from a JPEG image.\n<br><br>\nEXIF data embedded in photos usually contains information about the image file itself as well as the device used to create it.";
  21. this.inputType = "byteArray";
  22. this.outputType = "byteArray";
  23. this.args = [];
  24. }
  25. /**
  26. * @param {byteArray} input
  27. * @param {Object[]} args
  28. * @returns {byteArray}
  29. */
  30. run(input, args) {
  31. // Do nothing if input is empty
  32. if (input.length === 0) return input;
  33. try {
  34. return removeEXIF(input);
  35. } catch (err) {
  36. // Simply return input if no EXIF data is found
  37. if (err === "Exif not found.") return input;
  38. throw new OperationError(`Could not remove EXIF data from image: ${err}`);
  39. }
  40. }
  41. }
  42. export default RemoveEXIF;