Node.js 调整图像节点js Imagemagick的大小
我将ImageMagick模块与node js一起使用,以便对图像进行一些修改(调整大小)。这段代码的问题是不断出现此错误Node.js 调整图像节点js Imagemagick的大小,node.js,imagemagick,Node.js,Imagemagick,我将ImageMagick模块与node js一起使用,以便对图像进行一些修改(调整大小)。这段代码的问题是不断出现此错误 Error: Command failed: Paramtre non valide - /butterfly.jpg at ChildProcess.<anonymous> (C:\xxx\xxxx\Image-manipulation-using-NodeJS-and-imagemagick-master\node_modules\imagemagick\i
Error: Command failed: Paramtre non valide - /butterfly.jpg
at ChildProcess.<anonymous> (C:\xxx\xxxx\Image-manipulation-using-NodeJS-and-imagemagick-master\node_modules\imagemagick\imagemagick.js:88:15)
at ChildProcess.emit (events.js:321:20)
at maybeClose (internal/child_process.js:1026:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {
timedOut: false,
killed: false,
code: 4,
signal: null
}
使用node调整图像大小有什么想法或更好的解决方案吗?
致以最诚挚的问候我使用夏普压缩图像,因为它具有较小的依赖性,这对生产环境有好处。此外,它使用方法调用而不是发送JSON对象,JSON对象让您控制首先发生的操作。下面是我正在使用的代码的要点 下面是gist中提供的完整代码示例
var sharp = require('sharp');
const fs = require('fs');
const paths = require('path');
const pipeline = await sharp(path).rotate().resize({width: 1500});
pipeline
.webp()
.toFile(`${compressed}.webp`,
function (err) { //note the directory needs to exist else will throw err
if (err) console.log(err,`Illegal file : ${name}${ext}`)
});
我使用sharp压缩图像,因为它具有较小的依赖性,这对生产环境有好处。此外,它使用方法调用而不是发送JSON对象,JSON对象让您控制首先发生的操作。下面是我正在使用的代码的要点 下面是gist中提供的完整代码示例
var sharp = require('sharp');
const fs = require('fs');
const paths = require('path');
const pipeline = await sharp(path).rotate().resize({width: 1500});
pipeline
.webp()
.toFile(`${compressed}.webp`,
function (err) { //note the directory needs to exist else will throw err
if (err) console.log(err,`Illegal file : ${name}${ext}`)
});
我可以遵循的任何想法或可用项目您没有获得有效的图像,很可能是因为路径错误。我可以遵循的任何想法或可用项目您没有获得有效的图像,很可能是因为路径错误。