使用Jquery检查图像宽度

时间:2015-06-01 20:25:01

标签: javascript jquery json file-upload width

我在这里有一些代码,用于检查我网站上图片库上传工具的方案。目前我想检查尺寸要求,扩展名,我还想为图像设置最小宽度,如果那些不符合我的细节,我会提醒用户。我在制作图像的最小宽度方面遇到了麻烦,无法在互联网上找到任何真正有用的信息来回答我的问题,我可以用js查看图像宽度吗?

jQuery.noConflict();
jQuery(document).ready(function ($) {
$('#fileupload').fileupload({
    dataType: 'json',
    add: function (e, data) {
        var goUpload = true;
        var uploadFile = data.files[0];
        if (!(/\.(gif|jpg|jpeg|tiff|png)$/gi).test(uploadFile.name)) {
            alert('You must select an image file only');
            goUpload = false;
        }
        if (uploadFile.size > 2000000) { // 2mb
            alert('Please upload a smaller image, max size is 2 MB');
            goUpload = false;
        }
        if (uploadFile.width() < 500) { // min width = 500px
            alert('Please upload an image with a width greater than 500 px');
            goUpload = false;
        }
        if (goUpload == true) {
            data.submit();
        }
    },

0 个答案:

没有答案