2016-08-14 4 views
0

を得る私のコードです:私は、画像の幅と高さを取得したいとも私は、アップロードされようとしているビデオの解像度を取得したいJavascriptが画像の幅、高さ、ここでは、ビデオの解像度

if($('#profileimg').val()) 
    { 
     var fsize = $('#profileimg')[0].files[0].size; //get file size 
     var ftype = $('#profileimg')[0].files[0].type; // get file type 
     if(fsize>5242880) 
     { 
      $("#filetype").html("<b> Profile Image "+bytesToSize(fsize) +"</b> <br />File is too big, it should be less than 5 MB."); 
      return false 
     } 
     if(filetypeimage(ftype)) 
     { 
      var file, img; 
     if ((file = $('#profileimg')[0])) { 
     img = new Image(); 
     img.onload = function() { 
      alert(this.width + " " + this.height); 
     }; 
     img.onerror = function() { 
      alert("not a valid file: " + file.type); 
     }; 
     img.src = _URL.createObjectURL(file); 


     } 

私たちのサーバーに。事前に

おかげ

+0

あなたの質問は何ですか? –

+0

@Div質問は、私は画像の幅と高さ、画像の寸法を取得したいと非常に明確ですか? –

+1

[これを参照してください](http://stackoverflow.com/questions/623172/how-to-get-image-size-height-width-using-javascript) –

答えて

0

window.URL = window.URL || window.webkitURL; 
 

 

 
$('#submit').on('click',function(e){ 
 
    e.preventDefault(); 
 
    var fileInput = $('#file')[0], 
 
     file = fileInput.files && fileInput.files[0]; 
 

 
    if(file) { 
 
     var img = new Image(); 
 
     img.src = window.URL.createObjectURL(file); 
 
     img.onload = function() { 
 
      var width = img.naturalWidth, 
 
       height = img.naturalHeight; 
 

 
      window.URL.revokeObjectURL(img.src); 
 
      alert(width +" "+ height); 
 
     }; 
 
    }  
 

 
}); 
 

 

 
// you can validate on file change also 
 
$("#file").change(function(e) { 
 
    var file, img; 
 

 
    if ((file = this.files[0])) {   
 
     img = new Image(); 
 
     console.log(this); 
 
     img.onload = function() { 
 
      alert(this.width + " " + this.height); 
 
     }; 
 
     img.onerror = function() { 
 
      alert("not a valid file: " + file.type); 
 
     }; 
 
     img.src = window.URL.createObjectURL(file); 
 

 
    } 
 
});
<!DOCTYPE html> 
 
<html> 
 
<body> 
 
<form action="#" method="post"> 
 
    <input type="file" id="file" /> 
 
    <input type="submit" id="submit" /> 
 
</form> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
</body> 
 
</html>

関連する問題