JS 이미지 크기 측정 인스턴스

1820 단어
 
   
  


 

 
   <br>  var maxSize=document.getElementByIdx_x('MAX_FILE_SIZE').value; <br><br>function checkFileType(obj){<br><br>var path=obj.value.toString();<br><br>var perfix=path.substring(path.indexOf('.')+1);<br><br>var regExp=/(jpg|jpeg|gif|png)/gi;<br><br>if(perfix.match(regExp)){<br><br>checkFileSize(obj); // 。<br><br>}else{<br><br>alert(' , '); return false;<br><br>} } <br>function checkFileSize(obj){<br><br>var img=new Image();<br><br>try{<br><br>var imgSize=obj.files.item(0).fileSize;<br><br>return isLarged(imgSize,maxSize);// 。<br><br>}catch(e){ try{<br><br>img.src=obj.value;<br><br>return isLarged(img.fileSize,maxSize);<br><br>}catch(e){<br><br>obj.select();<br><br>var path=document.selection.createRange.text();<br><br>img.src=path;<br><br>return isLarged(img.fileSize,maxSize);<br><br>} } } <br>function isLarged(imgSize,maxSize){<br><br>if(imgSize>maxSize){<br><br>alert(' , '+parseInt(maxSize/1024)+'Kb');<br><br>return false;<br><br>}else{<br><br>alert(parseInt(imgSize/1024)+ 'kb ' + 'This large is OK');<br><br>return true;<br><br>} }

좋은 웹페이지 즐겨찾기