javascript - How to get file size of newly created Image() if src is base64 string? -
how can size of newly created new image()
in bytes if image's src
base64
data image?
i have such coffeescript code:
# string received after original image preprocessing base64string = "data:image/jpeg;base64......" newimageobj = new image() newimageobj.src = base64string newimageobj.onload = -> console.log "resized image width " + this.width console.log "new file size in bytes " + newimageobj.filesize
the output this:
resized image width 500 new file size in bytes undefined
this newimageobj.filesize
undefined
.
i'd use above, work correctly in case data isn't formatted correctly (eg, '=' missing, gets decoded correctly anyway)
new buffer(base64string, 'base64').length
Comments
Post a Comment