    /**
     * 获得base64
     * @param {Object} obj
     * @param {Number} [obj.width] 图片需要压缩的宽度，高度会跟随调整
     * @param {Number} [obj.quality=0.8] 压缩质量，不压缩为1
     * @param {Function} [obj.before(this, blob, file)] 处理前函数,this指向的是input:file
     * @param {Function} obj.success(obj) 处理后函数
     * @example
     *
     */
    $.fn.localResizeIMG = function (obj) {
  	
        this.on('change', function () {
        	      	
            var file = this.files[0];
            
            //alert("file: " + file);
            
            var rFilter = /^(image\/jpeg|image\/png)$/i; // 检查图片格式
    		if (!rFilter.test(file.type)) {
    			showMessage("图片格式有误！");
    			return;
    		}         
            var URL = URL || webkitURL;
            var blob = URL.createObjectURL(file);
            if($.isFunction(obj.before)) { obj.before(this, blob, file) };
            _create(blob, file);
            this.value = ''; 
        });

        /**
         * 生成base64
         * @param blob 通过file获得的二进制
         */
        function _create(blob,file) {
            var img = new Image();
            img.src = blob;
            img.onload = function () {
                var that = this;

                //生成比例
                var w = that.width,
                    h = that.height,
                    scale = w / h;
                w = obj.width || w;
                h = w / scale;
                var Orientation = null;
                //生成canvas
                var canvas = document.createElement('canvas');
                var ctx = canvas.getContext('2d');
                $(canvas).attr({width : w, height : h});
                ctx.drawImage(that, 0, 0, w, h);
                EXIF.getData(file,function() {
        			EXIF.getAllTags(this);
        			Orientation = EXIF.getTag(this, 'Orientation');
        			var mpImg = new MegaPixImage(img);
    				mpImg.render(canvas, {
    					maxWidth : 800,
    					maxHeight : 1200,
    					quality : 0.6,
    					orientation : Orientation
    				});
        		});
				var base64 = canvas.toDataURL('image/jpeg', obj.quality || 0.8 );
                // 生成结果
                var result = {
                    base64 : base64,
                    clearBase64: base64.substr( base64.indexOf(',') + 1 )
                };
                // 执行后函数
                obj.success(result);
            };
        }
    };