我想在react端使用imagemagick调整上传图像的大小(降低质量)。但是它的函数不工作,出现了错误。
var im = require('imagemagick');
im.resize({
srcPath: event.target.files[0],
dstPath: 'kittens-small.jpg',
width: 256
}, function(err, stdout, stderr){
if (err) throw err;
console.log('resized kittens.jpg to fit within 256x256px');
});这些错误总是会出现。
TypeError: childproc.spawn is not a function
}
24 | }
25 |
> 26 | var child = childproc.spawn(file, args);
| ^ 27 | var killed = false;
28 | var timedOut = false;发布于 2019-07-05 15:37:31
您不能在浏览器环境中使用imagemagic。正如在模块自述文件中提到的,its for Node JS。
我猜代码想要从你的节点进程中产生一个子进程来执行图像魔术。但是,因为您是在浏览器中,所以没有进程可以从中派生一个子进程。
要在浏览器中调整图像的大小,可以使用canvas。
https://stackoverflow.com/questions/56898192
复制相似问题