Node.js convert HEIC file

本秂侑毒 提交于 2020-12-12 05:12:07

问题


I need a way to use Node.js to convert a photo from HEIC format to either jpg or png. I have searched and cannot seem to find anything that works.


回答1:


npm -i heic-convert

const convert = require('heic-convert');
async function heicToJpg(file, output) {
    console.log(file, output);
    const inputBuffer = await promisify(fs.readFile)(file);
    const outputBuffer = convert({
        buffer: inputBuffer, // the HEIC file buffer
        format: 'PNG', // output format
    });
    return promisify(fs.writeFile)(output, outputBuffer);
}



回答2:


Changing the filename is sufficient for viewing HEIC as jpg:

const fileName = photo.fileName.split(".")[0] + ".jpg";



来源:https://stackoverflow.com/questions/60018547/node-js-convert-heic-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!