Image.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import * as ExifParser from "exif-parser";
  2. import Utils from "../Utils.js";
  3. /**
  4. * Image operations.
  5. *
  6. * @author tlwr [toby@toby.codes]
  7. * @copyright Crown Copyright 2017
  8. * @license Apache-2.0
  9. *
  10. * @namespace
  11. */
  12. const Image = {
  13. /**
  14. * Extract EXIF operation.
  15. *
  16. * Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
  17. *
  18. * @param {byteArray} input
  19. * @param {Object[]} args
  20. * @returns {string}
  21. */
  22. runEXIF(input, args) {
  23. try {
  24. const bytes = Uint8Array.from(input);
  25. const parser = ExifParser.create(bytes.buffer);
  26. const result = parser.parse();
  27. let lines = [];
  28. for (let tagName in result.tags) {
  29. let value = result.tags[tagName];
  30. lines.push(`${tagName}: ${value}`);
  31. }
  32. const numTags = lines.length;
  33. lines.unshift(`Found ${numTags} tags.\n`);
  34. return lines.join("\n");
  35. } catch (err) {
  36. throw "Could not extract EXIF data from image: " + err;
  37. }
  38. },
  39. };
  40. export default Image;