javascript - 如何使用 nodeca/pica 和 React 在客户端调整图像大小?
问题描述
我正在尝试使用 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)
解决方案
问题是我不应该使用 JSX 来构建画布。以下解决方案效果很好:
const resizedCanvas = document.createElement('canvas')
resizedCanvas.height = 500
resizedCanvas.width = 500
推荐阅读
- php - 注意:未定义的偏移量:1 在 webservice/dispatcher.php prestashop webservice 的第 36 行
- oauth-2.0 - 如何在 OIDC/OAuth2 流程中识别“资源服务器”上的“客户端应用程序”
- python - 如何使用这种特定的 Pandas 绘图格式设置标题大小
- javascript - 如何更改图表js中列的颜色
- php - 在 php 中的 if else 内部回显
- python - 从决策树回归器拟合训练数据会导致崩溃
- python - 使用 lark 解析器(ebnf 语法)解析罗马数字时出现 UnexpectedCharacters 错误
- spring - Spring Boot 中的 TransientPropertyValueException
- routes - GET 和列表集合的 ServiceStack 路由
- javascript - 在构建脚本中使用 Babel 时,如何为生产部署设置依赖项?