我正在尝试使用画布进行图像压缩,但野生动物园无法正常工作。 Google chrome效果很好。
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中不起作用。
但是我找不到其他选择。