zoukankan      html  css  js  c++  java
  • jquery 读取file 图片文件的宽高

    if (file) {
                            var reader = new FileReader();
                            reader.onload = function(e) {
                                var sourceid = $("input[name='rdsource']:checked").val();
                                if (sourceid == 20) {
                                    //实拍图限定宽高为3000*2000
                                    var data = e.target.result;
                                    //加载图片获取图片真实宽度和高度
                                    var image = new Image();
                                    image.onload = function() {
                                        var width = image.width;
                                        var height = image.height;
                                        if (width == 3000 && height == 2000) {
                                            var fileSize = (file.size / 1024 / 1024).toFixed(2);
                                            html = html + '<tr id="' + i + '"><td><strong>' + file.name + '</strong></td>' +
                                                '<td>' + fileSize + 'MB</td><td><div id="uploadProgress_' + i + '" class="upload_progress" style="display:none;0px;height:15px;text-align:right;vertical-align:middle" ></div></td><td><a href="javascript:void(0);" class="upload_delete" title="删除" data-index="' + i + '">删除</a></td></tr>';
                                            totalSize += (fileSize * 1);
                                            i++;
                                            funAppendImage();
                                        } else {
                                            alert("图片:" + file.name + ",尺寸不是3000*2000");
                                            files.splice(jQuery.inArray(file, files), 1);
                                            funAppendImage();
                                        }
                                    };
                                    image.src = data;
                                } else {
                                    var fileSize = (file.size / 1024 / 1024).toFixed(2);
                                    html = html + '<tr id="' + i + '"><td><strong>' + file.name + '</strong></td>' +
                                        '<td>' + fileSize + 'MB</td><td><div id="uploadProgress_' + i + '" class="upload_progress" style="display:none;0px;height:15px;text-align:right;vertical-align:middle" ></div></td><td><a href="javascript:void(0);" class="upload_delete" title="删除" data-index="' + i + '">删除</a></td></tr>';
                                    totalSize += (fileSize * 1);
                                    i++;
                                    funAppendImage();
                                }
                                //--------------
                            };
                            reader.readAsDataURL(file);
                        } 

    file控件,在js中读取图片宽高,需要异步实例化图片,然后读取图片的宽高

  • 相关阅读:
    [导入]Interesting Finds: 2007.12.17
    [导入]Interesting Finds: 2007.12.15
    [导入]Interesting Finds: 2007.12.13
    Interesting Finds: 2007.12.22
    吾生也有涯,而知也无涯。
    Hello world
    学习了clipboard复制剪切插件的使用
    在博客园学习成长
    命名空间概述
    Linux vi/vim
  • 原文地址:https://www.cnblogs.com/bwlang/p/6904913.html
Copyright © 2011-2022 走看看