Using JavaScript-Load-Image library to load an image from a file and it quadruples the size of the image

760 views Asked by At

Using JavaScript-Load-Image function loadImage(...). But the base64 string is roughly 2-4x longer than loading it via FileReader().

I'm already dealing with large files so they cannot be so much larger.

var reader = new FileReader();
reader.onload = function() {
    console.log('initial length:', this.result.length);
};
reader.readAsDataURL(image_file);

vs.

loadImage(
        file,
        function (img) {
            console.log('resized length:', img.toDataURL().length);
        },
        {
            orientation: true
        }
    );

some results:

24839 vs. 107482

2498383 vs. 5898430

2391783 vs. 5955498

1

There are 1 answers

0
benwiz On

img.toDataURL() needed to be img.toDataURL('image/jpeg) to force saving as more compressed jpg instead of png