Как используя nmpjs конвертировать JPG base64 в webp base64 или же прямо в файл?

Конвертирую картинку JPG формата в WEBP формат.

Поставил npmjs модуль https://www.npmjs.com/package/webp-converter на node 18.

Поставил в перем [[PYT]] - путь к jpg файлу вот такой: C:\Users\username\Downloads\777\1c.jpg

Но в переменную[[ITOG]] не сохраняется ничего (она пустая).

И использую из офиц доков такой пример для: Convert base64 image to webpbase64 image

        const webp=require('webp-converter');
    const fs=require('fs');
    const path=[[PYT]];
    function get_webpbase64(path) {
    fs.readFile(path, function (error, data) {
      if (error) {
        throw error;
      } else {
        let buf = Buffer.from(data);
        let dataBase64 = Buffer.from(buf).toString('base64');
          // base64str of image
        // base64str image type jpg,png ...
        //option: options and quality,it should be given between 0 to 100
        let result = webp.str2webpstr(dataBase64,"jpg","-q 80");
        [[ITOG]]=result;
        result.then(function(result) {
          // you access the value from the promise here
              console.log(result)
            });
      }
    });
    }
    // use the default temp path for conversion
    get_webpbase64("./nodejs_logo.jpg")
    // use the custom temp path for conversion
    get_webpbase64("./nodejs_logo.jpg","/home/user/Desktop/webp/temp")

Но в переменную [[ITOG]] не сохраняется ничего (она пустая)


Ответы (0 шт):