/**
* 使用canvas压缩照片
* @param img 需要压缩的照片
* @param Orientation 照片原始方向
* @returns {string} base64格式照片数据
*/
function compress(img, Orientation) {
var canvas =document.createElement("canvas");
var ctx = canvas.getContext('2d');
//瓦片canvas
var tCanvas =document.createElement("canvas");
var tctx = tCanvas.getContext("2d");
// var initSize = img.src.length;
var width = img.width;
var height = img.height;
//图片像素大于400万像素,计算压缩到400万以下
var ratio;
if ((ratio = width * height /4000000) >1) {
ratio = Math.sqrt(ratio);
width /= ratio;
height /= ratio;
}else {
ratio =1;
}
canvas.width = width;
canvas.height = height;