jQuery,画布图像裁剪-索引或大小为负或大于允许的数量

jQuery & Canvas Image Crop - Index or size is negative or greater than the allowed amount

本文关键字:小为 大于 索引 布图像 图像 裁剪 jQuery      更新时间:2023-09-26

我已经安装了CodeCanyon的Canvas图像裁剪插件,我在firefox中遇到了一个问题。

我上传的一些(不是全部)图像出现以下错误:索引或大小为负或大于允许的数量

我使用的是HTML5 canvas版本的插件

我发现了错误,它是firefox不允许分数/0在画布drawImage调用。

所以你需要在JS中找到以下行:
ctx.drawImage(img, x, y, w, h, 0, 0, width, height);

,并在它前面加上这个来四舍五入:

w = Math.round(w);
h = Math.round(h);
width = Math.round(width);
height = Math.round(height);
ctx.drawImage(img, x, y, w, h, 0, 0, width, height);

应该可以解决这个问题

希望这能在某些时候帮助到其他人!