gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 20:23:20 37 4
gpt4 key购买 nike

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

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)

最佳答案

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

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

关于javascript - 如何使用 nodeca/pica 和 React 在客户端调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51216681/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com