Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unknown tag type" when trying to write a modified tiff #114

Open
Erik-at-work opened this issue Jan 22, 2023 · 0 comments
Open

"unknown tag type" when trying to write a modified tiff #114

Erik-at-work opened this issue Jan 22, 2023 · 0 comments

Comments

@Erik-at-work
Copy link

Erik-at-work commented Jan 22, 2023

I am trying to create a web page that takes a TIFF file, modifies each pixel and provides the modified file. But I get "unknown tag type". What is wrong? Here is the code:

<!DOCTYPE html>
<html>
  <head>
    <title>Modify tiff</title>
  </head>
  <body>
    <script src="UTIF.js"></script>
    <input type="file" id="fileSelector", accept="image/tiff">
    <script>
      document.getElementById('fileSelector').onchange = event => {
        const tiffFile = event.target.files[0];
        const reader = new FileReader();
        reader.onload = () => {
            const tiffData = reader.result;
            const ifds = UTIF.decode(tiffData);
            const newPages = [];
            for (let page = 0; page < ifds.length; ++page) {
              UTIF.decodeImage(tiffData, ifds[page]);
              const w = ifds[page].width;
              const h = ifds[page].height;
              const imgData = UTIF.toRGBA8(ifds[page]);
              for (let i = 0; i < imgData.length; ++i) imgData[i] = (imgData[i] + 1) % 2;
              newPages.push(UTIF.encodeImage(imgData, w, h));
            }
            const newFile = new File([UTIF.encode(ifds)], 'modified.tif', { type : 'image/tiff' });
            console.log(newFile);
            const link = document.createElement('a');
            link.style.display = 'none';
            link.href = URL.createObjectURL(newFile);
            link.download = 'modified.tif';
            document.body.appendChild(link);
            link.click();
            link.remove();
          };
        reader.readAsArrayBuffer(tiffFile);
      }
    </script>
  </body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant