search

Home  >  Q&A  >  body text

javascript - How to get the file size of an image

<img src="https://img.biaoqing.com/stuff/2017/1/23/356154f62cc144a38fec7028765210a0.gif">

How to get the file size of this picture

三叔三叔2764 days ago950

reply all(5)I'll reply

  • 代言

    代言2017-06-14 10:55:48

    // 可以大致的知道图片的文件大小/精确大小需要获取responseHeaders的 content-length
    $.ajax({
        url:'https://img.biaoqing.com/stuff/2017/1/23/356154f62cc144a38fec7028765210a0.gif',
        success: function(data){
            console.log(data.length)
        }
    })

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-14 10:55:48

    Let the backend give it to you~ These are the static resources of the server

    reply
    0
  • PHP中文网

    PHP中文网2017-06-14 10:55:48

    Pass it to the background, just use size() in the background (in java)

    reply
    0
  • 扔个三星炸死你

    扔个三星炸死你2017-06-14 10:55:48

    After the pictures are loaded, can I just use JQ? If you want to know the image size before loading, there seems to be a new Image() or something?

    $('#info').html($('img').eq(0).width()+' ' +$('img').eq(0).height());

    reply
    0
  • PHP中文网

    PHP中文网2017-06-14 10:55:48

    Put it in inupt and you can get it

    reply
    0
  • Cancelreply