How to use this for image which is being fetched from online source, I am not looking for saving the file on disk before rotating.
abhinovpankaj opened this issue · 1 comments
abhinovpankaj commented
How to use this for image which is being fetched from online source, I am not looking for saving the file on disk before rotating.
abhinovpankaj commented
Written below code
try {
const resp = await fetch(
imageurl
);
if (resp.ok) {
const imagebuffer = resp.arrayBuffer
? await resp.arrayBuffer()
: await resp.buffer();
const extension = path.extname(imageurl);
//fix image rotation
try {
var {buffer} = await jo.rotate(Buffer.from(imagebuffer), {quality:50});
return { height: 6.2,width: 4.85, data: buffer, extension: extension };
} catch (error) {
console.log('An error occurred when rotating the file: ' + error);
return { height: 6.2,width: 4.85, data: imagebuffer, extension: extension };
}
}else{
return;
}
} catch (error) {
console.log(error);
return ;
}