0

Is there a way to convert tiff files to png or jpg format in React or somehow view the tiff file in chrome? I tried to draw on canvas and get data url but it didn't work. I also tried tiff.js but got fs, path, crypto errors. The code below is the method I tried for the convert operation. Thanks for your helps.

Promise.all(promises)
  .then(values => {
     let images = [];
     values.forEach(res => {
        if (res.imageBuffer) {
           const blob = new Blob([new 
           Uint8Array(res.imageBuffer.Body.data)], { type: res.imageBuffer.ContentType });
           let url = URL.createObjectURL(blob);

           if (res.imageBuffer.ContentType === 'image/tiff') {
               var myCanvas = document.createElement('canvas');
               var ctx = myCanvas.getContext('2d');
               var img = new Image();
               img.onload = function () {
                   ctx.drawImage(img, 0, 0);
               };
               img.src = url;
               url = myCanvas.toDataURL()
            }

            images.push({
                blobURL: url,
                date: res.attachment_source_date,
                ...res,
            });
        }
    });

    setImages(images);
  })
  .catch(err => {
        console.error(err);
  });

enter image description here

Serhat
  • 15
  • 4
  • Does this answer your question? [How would I display a TIFF images in all web browsers?](https://stackoverflow.com/questions/2176991/how-would-i-display-a-tiff-images-in-all-web-browsers) – jsejcksn Nov 25 '22 at 08:30
  • Can you post the code that you tried but didn’t work? – Kokodoko Nov 25 '22 at 08:37

0 Answers0