scionoftech / webp-converter

[DEPRECATED] A small node.js library for converting any image to webp file format or converting webp image to any image file format.
MIT License
229 stars 43 forks source link

Error! Unknown option '-' #24

Open linen1996 opened 4 years ago

linen1996 commented 4 years ago

I directly run cwebp.exe like this bat code, it works, but the JavaScript code webpConverter.cwebp(input, output, options, callback), it got error Error! Unknown option '-'.

:: bat code
D:\Workspaces\front-end\project\image2html\node_modules\webp-converter/lib/libwebp_win64/bin/cwebp.exe -q 75 "D:/Workspaces/front-end/project/image2html/images/4 - 28172-1565573276-704911963.png" -o "D:/Workspaces/front-end/project/image2html/images/imagemin/4 - 28172-1565573276-704911963.webp"
// JavaScript code
let imageDirPath = 'D:/Workspaces/front-end/project/image2html/images'
let imageminRelativeFolder = 'imagemin'

function getImageminDir (dirPath) {
  return `${imageDirPath}/${imageminRelativeFolder}`
}

function toWebp (file) {
  let input = `"${imageDirPath}/${file}"`
  let output = `"${getImageminDir()}/${util.replaceExtnameToWebp(file)}"`
  let options = `-q 75`
  let callback = function (status, error) {
    if (status == 101) {
      console.log('101, error)
    }
  }
  webpConverter.cwebp(input, output, options, callback)
}