用jquery來獲得上傳圖片的尺寸


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用jquery來獲得上傳圖片的尺寸的</title>
</head>
<body>
    <input type="file" id="image_file" multiple>
    <script src="./lib/jquery-1.8.0.min.js"></script>
    <script>
        //獲取input圖片寬高和大小
        function getImageWidthAndHeight(id, callback) {
          var _URL = window.URL || window.webkitURL;
          $("#" + id).change(function (e) {
            var file, img;
            if ((file = this.files[0])) {
              img = new Image();
              img.onload = function () {
                callback && callback({"width": this.width, "height": this.height, "filesize": file.size});
              };
              img.src = _URL.createObjectURL(file);
            }
          });
        }
        
        getImageWidthAndHeight('image_file', function (obj) {
           console.log('width:'+obj.width+'-----height:'+obj.height);
          });
    </script>
    <script></script>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM