Get the IMG to view size
var
img_url =
‘http://img5.imgtn.bdimg.com/it/u=4267222417,1017407570&fm=200&gp=0.jpg‘
// 创建img对象
var
img =
new
Image();
// 改变图片的src
img.src = img_url;
// 加载完成执行
img.onload =
function
(){
// 打印
alert(
‘width:‘
+img.width+
‘,height:‘
+img.height);
That's it.
Get the size of the current picture
<body> <br/> <input type= " File "onchange=" Selectimage (this); "/> <br/> <input type=" button "onclick=" Uploadimage (); " Value= "Submit"/> <script> var image = '; The value of function selectimage (file) { console.log (file.files)//output is as follows:
Console.log (file.files[0].size)//Get size
The output is byte 1kb = 1024b so you want to convert the words will be parseint (file.files.size/1024)//Such a result is the KB if (!file.files | |!file. Files[0]) {return; } var reader = new FileReader (); Reader.onload = function (evt) {document.getElementById (' image '). src = evt.target.result; image = Evt.target.result; } reader.readasdataurl (File.files[0]); } function Uploadimage () {$.ajax ({type: ' POST ', url: ' admin.php ', Data: {image:image}, Async:false, DataType: ' JSON ', success:fun Ction (data) {Consoel.log (data) if (data.success) {alert (' upper Success '); } else {alert (' upload failed '); }}, Error:function (err) {Console.log (ERR) Alert (' Network Fault '); } }); } </script></body>
Know so much, there is no place to ask God to guide twos
JS Get picture width height and picture size