2017-04-25 48 views
1

我正在使用blueimp/jQuery-File-Upload插件在我的网站上的客户端上载和调整图像大小。Jquery-fileupload在调整大小之前获取原始文件大小

我需要一种方法来获取原始上传的图像尺寸,然后将其调整为我在imageMaxWidth和imageMaxHeight选项中提供的值。

任何帮助或指导将是伟大的,或者我可以编辑库并添加该钩子,如果它不在那里返回原始文件数据。

在此先感谢。

+0

找到可能有帮助的解决方案吗? –

+0

在库中添加了钩子 –

回答

1

只是发现了一些不添加自定义挂钩:

只重写从文件对象添加方法和计算图像尺寸,例如:

add: function(e, data) { 
var img = new Image; 
var _URL = window.URL || window.webkitURL; 
img.onload = function() { 
    sizes = 
    width: this.width 
    height: this.height 
}; 
img.src = _URL.createObjectURL(data.files[0]); 

//below code is to let the library further process file e.g resize etc 
var $this = $(this); 
return data.process(function() { 
    return $this.fileupload('process', data); 
}).done(function() { 
    return data.submit(); 
}); 

}

在这里,你拥有了它,在大小散列。

干杯!

相关问题