javascript - DropzoneJS-索引大小错误: Index or size is negative or greater than the allowed amount

标签 javascript firefox dropzone.js drawimage

我开始使用DropzoneJS这是一个很棒的开源库 7,043 starsGithub 。它提供带有图像预览的拖放文件上传。

但是,上传超过 100k 的图像会导致 Firefox 出现以下错误:

IndexSizeError: Index or size is negative or greater than the allowed amount

dropzone.js 中,在以下行中引发:

return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);

其他人报告说在创建缩略图时遇到了这种行为 here

经过一番研究后,这是 Firefox 中的一个常见错误。最相关的 stackoverflow 问题:

1- Canvas - IndexSizeError: Index or size is negative or greater than the allowed amount

最佳答案

按照此快速操作后解决了我的问题 fix

基本被替换:

return ctx.drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh / vertSquashRatio);

与:

return ctx.drawImage(img, Math.round(sx), Math.round(sy), Math.round(sw), Math.round(sh), Math.round(dx), Math.round(dy), Math.round(dw), Math.round(dh) / vertSquashRatio);

在我的dropzone.js

关于javascript - DropzoneJS-索引大小错误: Index or size is negative or greater than the allowed amount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28036297/

相关文章:

javascript - 在元素内创建新元素

javascript - 如何在 React JSX 中打印子字符串?

javascript 添加月份至今

javascript - 使用多个搜索框过滤单个表格

firefox - 如何在 Chrome 和 Firefox 中使用 YouTube iFrame API?

javascript - Canvas 在浏览器之间是否有不同的抗锯齿功能?

javascript - Dropzone.js 阻止 Flask 渲染模板

javascript - 将多个cookie值作为变量从background.js传递到contentscript.js

javascript - Firefox 扩展 : check if window is minimized

javascript - Dropzone.js "Undefined index: file"如何与 Laravel 一起使用?