标签:
直接上代码
plupload.addFileFilter(‘min_width‘, function (maxwidth, file, cb) { var self = this, img = new o.Image(); function finalize(result) { // cleanup img.destroy(); img = null; // if rule has been violated in one way or another, trigger an error if (!result) { self.trigger(‘Error‘, { code: plupload.IMAGE_DIMENSIONS_ERROR, message: "图片宽度不能小于" + maxwidth + "px", file: file }); } cb(result); } img.onload = function () { // check if resolution cap is not exceeded finalize(img.width >= maxwidth); }; img.onerror = function () { finalize(false); }; img.load(file.getSource()); }); plupload.addFileFilter(‘filetype‘, function (filetype, file, cb) { var self = this, img = new o.Image(); function finalize(result) { // cleanup img.destroy(); img = null; // if rule has been violated in one way or another, trigger an error if (!result) { self.trigger(‘Error‘, { code: plupload.IMAGE_DIMENSIONS_ERROR, message: "您上传的图片格式是" + file.type + ",只能上传jpg图片", file: file }); } cb(result); } img.onload = function () { // check if resolution cap is not exceeded var type = file.type; type = type.replace("image/", ""); finalize(filetype.indexOf(type) > 0); }; img.onerror = function () { finalize(false); }; img.load(file.getSource()); }); var uploader = new plupload.Uploader({//创建实例的构造方法 browse_button: ‘fileinput-button‘, runtimes: ‘html5,flash,silverlight,html4‘, //上传插件初始化选用那种方式的优先级顺序 url: "/common/ImageUp", //远程上传地址 max_file_size: ‘20mb‘, chunk_size: ‘500kb‘, filters: { title: "Image files", filetype: "jpg,jpeg", min_width: 600 } , flash_swf_url: ‘/Scripts/plupload-2.1.9/Moxie.swf‘, }); uploader.init();
参考文章:
http://stackoverflow.com/questions/14091505/control-image-width-and-height-when-upload-image
标签:
原文地址:http://www.cnblogs.com/xcsn/p/5764241.html