zoukankan      html  css  js  c++  java
  • js上传图片获取原始宽高

    以vue上传图片为例:

    <template>
      <div>
        <input type="file" @change="uploadFile($event)" multiple="multiple" />
      </div>
    </template>
     
    <script>
      export default {
        name: 'upload',
        data () {
          return {
            imgInfo: {}
          }
        },
        methods:{
          uploadFile(event){
            let that = this;
            let file = event.target.files[0];
            let fileReader = new FileReader();
            fileReader.readAsDataURL(file); //根据图片路径读取图片
            fileReader.onload = function(e) {
              let base64 = this.result;
              let img = new Image();
              img.src = base64;
              img.onload = function() {
                that.imgInfo = {
                   img.naturalWidth,
                  height: img.naturalHeight
                };
                console.log("宽:" + img.naturalWidth + " 高:" + img.naturalHeight);
              }
            }
          }
        }
      }
    </script>
  • 相关阅读:
    wkhtmktopdf
    linux命令行抓取网页快照
    ubuntu 固定静态IP
    $http questions
    generate_scripts
    network
    IT_Qestion
    day03
    day02
    day01
  • 原文地址:https://www.cnblogs.com/ysx215/p/11950423.html
Copyright © 2011-2022 走看看