Javascript resize base64 image


I have a function that send a base64 image to my input, but I want to resize the image before send to input. I need a 250×250 image, but when take shot from mobile the image goes 3096×3096…
There is my code:

function sendPhoto() {

            if (this.files && this.files[0]) {

                var FR = new FileReader();

                FR.addEventListener("load", function (e) {
                    var permitted_files = ['image/png', 'image/jpeg', 'image/bmp'];
                    var baseImg = e.target.result;
                    var parteImg = baseImg.substring(11, 15);

                    if (((parteImg).includes('jpeg')) || ((parteImg).includes('png')) || ((parteImg).includes('bmp'))) {
                        document.getElementById("sendedPhoto").src = e.target.result;
                        document.getElementById("btnPhoto").style.display = '';
                    } else {
                        $("body").overhang({
                            type: "error",
                            message: "This is not an image file."
                        });
                        document.getElementById("uploadFoto").value = "";
                    }
                });

                FR.readAsDataURL(this.files[0]);
            }

        }

Any ideas? THX!

Source: JavaSript – Stack Overflow

November 28, 2021
Category : News
Tags: base64 | html | javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.