如何使用nodeca/pica和React调整客户端图像大小?

zor*_*rro 5 javascript reactjs

我正在尝试使用 nodeca/pica 库将图像发送到服务器到 React 中的画布之前调整图像大小:

import pica from 'pica'

let resizedCanvas = <canvas height={500} width={500}/>

  pica().resize(myImage, resizedCanvas, {
  unsharpAmount: 80,
  unsharpRadius: 0.6,
  unsharpThreshold: 2
}).then(result => console.log(`resize done!  ${result}`))
    .catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)

但我在控制台中收到以下错误:

TypeError: stages.shift is not a function or its return value is not iterable
at processStages (index.js:508)
at init.then (index.js:549)
Run Code Online (Sandbox Code Playgroud)

zor*_*rro 6

问题是我不应该使用 JSX 来构建画布。以下解决方案效果很好:

const resizedCanvas = document.createElement('canvas')
resizedCanvas.height = 500
resizedCanvas.width = 500
Run Code Online (Sandbox Code Playgroud)