function cutPhoto(url)
{//531 431
	getImageWidth(callback,url);
}
function getImageWidth(callback,url)
{
    var img = new Image();
  	img.src = url;
		
    // 如果图片被缓存，则直接返回缓存数据
    if(img.complete){
        callback(img.width, img.height,img);
    }else{
            // 完全加载完毕的事件
        img.onload = function(){
       	 callback(img.width, img.height,img);
        }
    }
}
function callback(w,h,img)
{
	var canvas = document.createElement("canvas");//document.getElementById("myCan");
	var zoom = getZoom(w,h);
	var rw = parseInt(w*zoom,10);
	var rh = parseInt(h*zoom,10);
	canvas.width = rw + ""; 
	canvas.height = rh + ""; 
	console.log(rw + " = " + canvas.height);
	(document.body).appendChild(canvas);
	var ctx = canvas.getContext('2d');
	//var w = 431;
	//var h = 531;
	ctx.drawImage(img,0,0,w,h,0,0,rw,rh);
	
	var imgData=ctx.getImageData(0,0,rw,rh);
	//document.getElementById("img").src = canvas.toDataURL("image/jpeg");
	var pData = canvas.toDataURL("image/jpeg");
	console.log(pData);
	//downLoad(pData);
	(document.body).removeChild(canvas);
}
function downLoad(url){
    var oA = document.createElement("a");
    oA.download = '';// 设置下载的文件名，默认是'下载'
    oA.href = url;
    document.body.appendChild(oA);
    oA.click();
    oA.remove(); // 下载之后把创建的元素删除
}
function getZoom(w,h)
{
	//110--122
	//768--1024
	var zoomW = 1;
	var zoomH = 1;
	var aW = new Array(240,768);
	var aH = new Array(320,1024);
	if(w < aW[0])
		return -1;
	else if(w >= aW[0] && w <= aW[1])
		zoomW = 1;
	else
		zoomW = (Math.floor(aW[1]/w*100))/100;
	
	if(h < aH[0])
		return -1;
	else if(h >= aH[0] && h <= aH[1])
		zoomH = 1;
	else
		zoomH = (Math.floor(aH[1]/h*100))/100;
	console.log("w="+w+",h="+h);	
	console.log("zoomW="+zoomW+",zoomH="+zoomH);
	return (zoomW > zoomH)?zoomH:zoomW;
}