Image file size from data URI in JavaScript

后端 未结 4 1233
野趣味
野趣味 2020-12-18 11:19

I am not sure it\'s even possible but - can I get the image file size from data URI?

For example, let\'s say there is an IMG element where src goes:

4条回答
  •  臣服心动
    2020-12-18 12:07

    Your best option is to calculate the length of the base64 string itself.

    What is a base64 length in bytes?

    You have to convert the base64 string to a normal string using atob() and then check it length, it will return a value that you can say is close to the actual size of the image. Also you don't need the data:image/jpeg;base64, part from the data URI to check the size.

提交回复
热议问题