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);
});