<legend id='yYOri'><style id='yYOri'><dir id='yYOri'><q id='yYOri'></q></dir></style></legend>
    <tfoot id='yYOri'></tfoot>
      <i id='yYOri'><tr id='yYOri'><dt id='yYOri'><q id='yYOri'><span id='yYOri'><b id='yYOri'><form id='yYOri'><ins id='yYOri'></ins><ul id='yYOri'></ul><sub id='yYOri'></sub></form><legend id='yYOri'></legend><bdo id='yYOri'><pre id='yYOri'><center id='yYOri'></center></pre></bdo></b><th id='yYOri'></th></span></q></dt></tr></i><div id='yYOri'><tfoot id='yYOri'></tfoot><dl id='yYOri'><fieldset id='yYOri'></fieldset></dl></div>
      • <bdo id='yYOri'></bdo><ul id='yYOri'></ul>

      <small id='yYOri'></small><noframes id='yYOri'>

    1. 如果 src 是 base64 字符串,如何获取新创建的 Image() 的文件大小?

      时间:2024-04-19
      • <bdo id='ORChv'></bdo><ul id='ORChv'></ul>

            1. <legend id='ORChv'><style id='ORChv'><dir id='ORChv'><q id='ORChv'></q></dir></style></legend><tfoot id='ORChv'></tfoot>

              • <small id='ORChv'></small><noframes id='ORChv'>

                <i id='ORChv'><tr id='ORChv'><dt id='ORChv'><q id='ORChv'><span id='ORChv'><b id='ORChv'><form id='ORChv'><ins id='ORChv'></ins><ul id='ORChv'></ul><sub id='ORChv'></sub></form><legend id='ORChv'></legend><bdo id='ORChv'><pre id='ORChv'><center id='ORChv'></center></pre></bdo></b><th id='ORChv'></th></span></q></dt></tr></i><div id='ORChv'><tfoot id='ORChv'></tfoot><dl id='ORChv'><fieldset id='ORChv'></fieldset></dl></div>
                  <tbody id='ORChv'></tbody>
                本文介绍了如果 src 是 base64 字符串,如何获取新创建的 Image() 的文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                How can I get the size of the newly created new Image() in bytes if this image's src is base64 data image?

                I have such coffeescript code:

                # This string is received after some original image preprocessing
                base64String = "data:image/jpeg;base64......"
                
                newImageObj = new Image()
                newImageObj.src = base64String
                newImageObj.onload = ->
                  console.log "Resized image width is " + this.width
                  console.log "New file size in bytes is " + newImageObj.fileSize
                

                The output is always like this:

                Resized image width is 500
                New file size in bytes is undefined
                

                This newImageObj.fileSize is always undefined.

                解决方案

                here is the algorithm to find file size from base64 string:

                base64String = "data:image/jpeg;base64......";
                
                var stringLength = base64String.length - 'data:image/png;base64,'.length;
                
                var sizeInBytes = 4 * Math.ceil((stringLength / 3))*0.5624896334383812;
                var sizeInKb=sizeInBytes/1000;
                

                这篇关于如果 src 是 base64 字符串,如何获取新创建的 Image() 的文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何配置 Rails 3.2+/4 默认生成 .js 而不是 .js.coffee? 下一篇:如何在 JavaScript 中创建 CoffeeScript 风格的存在运算符?

                相关文章

              • <small id='cTW9d'></small><noframes id='cTW9d'>

                <tfoot id='cTW9d'></tfoot>

                  <i id='cTW9d'><tr id='cTW9d'><dt id='cTW9d'><q id='cTW9d'><span id='cTW9d'><b id='cTW9d'><form id='cTW9d'><ins id='cTW9d'></ins><ul id='cTW9d'></ul><sub id='cTW9d'></sub></form><legend id='cTW9d'></legend><bdo id='cTW9d'><pre id='cTW9d'><center id='cTW9d'></center></pre></bdo></b><th id='cTW9d'></th></span></q></dt></tr></i><div id='cTW9d'><tfoot id='cTW9d'></tfoot><dl id='cTW9d'><fieldset id='cTW9d'></fieldset></dl></div>
                    <bdo id='cTW9d'></bdo><ul id='cTW9d'></ul>
                1. <legend id='cTW9d'><style id='cTW9d'><dir id='cTW9d'><q id='cTW9d'></q></dir></style></legend>