Determining image file size + dimensions via Javascript?

后端 未结 11 1246
执念已碎
执念已碎 2020-11-22 07:00

As part of a web app, once images have been downloaded and rendered on a web page, I need to determine an image\'s file size (kb) and resolution within the browser context (

11条回答
  •  爱一瞬间的悲伤
    2020-11-22 07:36

    Most folks have answered how a downloaded image's dimensions can be known so I'll just try to answer other part of the question - knowing downloaded image's file-size.

    You can do this using resource timing api. Very specifically transferSize, encodedBodySize and decodedBodySize properties can be used for the purpose.

    Check out my answer here for code snippet and more information if you seek : JavaScript - Get size in bytes from HTML img src

提交回复
热议问题