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

时间:2018-07-06 19:34:20

标签: 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))

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

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)

1 个答案:

答案 0 :(得分:1)

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

const resizedCanvas = document.createElement('canvas')
resizedCanvas.height = 500
resizedCanvas.width = 500