Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. class TiffImage {
  2. constructor(url) {
  3. this.imageURL = boardType;
  4. }
  5. this.width;
  6. this.height;
  7. this.canvas;
  8. this.xResolution;
  9. this.yResolution;
  10. }
  11.  
  12. async loadImage() {
  13. // retrieve tiff and convert it to an html5 canvas
  14. return fetch(this.imageURL)
  15. .then((response) => {
  16. return response.arrayBuffer();
  17. })
  18. .then((buffer) => {
  19. // handle tiff image
  20. let tiff = new Tiff({buffer: buffer});
  21. this.width = tiff.width();
  22. this.height = tiff.height();
  23.  
  24. // try to grab resolutions
  25. this.xResolution = tiff.getField(282);
  26. this.yResolution = tiff.getField(283);
  27.  
  28. console.log('xRes: ' + this.xResolution);
  29. // prints 'xRes: 1098514432'
  30. console.log('yRes: ' + this.yResolution);
  31. // prints 'yRes: 1081737216'
  32.  
  33. console.log('xRes as bin: ' + this.xResolution.toString(2);
  34. // prints 'xRes as bin: 1000001011110100000000000000000'
  35. console.log('yRes as bin: ' + this.yResolution.toString(2);
  36. // prints 'yRes as bin: 1000000011110100000000000000000'
  37.  
  38. this.canvas = tiff.toCanvas();
  39.  
  40. // do stuff with image
  41.  
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement