javascript - 使用画布压缩图像
问题描述
我正在尝试使用画布进行图像压缩,但 safari 无法正常工作。谷歌浏览器运行良好。
ResizeImage = function (base64data, index, size, orientation) {
jQuery("#" + self.canvas).after('<canvas style="display:none" id="UsedCanvas"></canvas>');
var canvas = document.getElementById("UsedCanvas");
var ctx = canvas.getContext("2d");
var image = new Image();
image.src = base64data;
image.onload = function () {
canvas.width = image.width;
canvas.height = image.height;
var height = canvas.height,
width = canvas.width;
if (orientation > 4) {
canvas.width = height;
canvas.height = width;
}
if (canvas.width > 1600 || canvas.height > 1200) {
if (canvas.width > canvas.height) {
var newheight = (1600 * canvas.height) / canvas.width;
canvas.height = newheight;
canvas.width = 1600;
} else {
var newwidth = (1600 * canvas.width) / canvas.height;
canvas.width = newwidth;
canvas.height = 1600;
}
}
ProcessNewImage(canvas.toDataURL('image/jpeg', 0.7));
};
};
根据我的研究,datatourl 参数质量不适用于 safari。
但我没有找到替代方案。
解决方案
推荐阅读
- reactjs - React 17.0.1 - 使用动态路径导入组件
- python - 以下代码会断开所有传入或传出的 PyQt 信号吗?
- flutter - Flutter Socket-Io 没有连接到服务器?
- haskell - 范畴论基础
- c++ - M1 Mac 上的 Tensorflow C api 立即出现运行时错误
- scheme - 为定义语法的 let 绑定寻找替代方案
- python - AttributeError: 'list' 对象没有属性 'loc'
- python - Jupyter 实验室更改 networkx 图形大小
- javascript - Tailwind.css — 如何使用 Tailwind 实现 last-child?
- sql - GROUP BY 还是 JOIN 更高效?