Jump to content

Upload e leitura de fotos


Gabriel

Recommended Posts

Boas, tenho o seguinte código abaixo que cria um filtro para uma foto.

let canvas = document.getElementById('canvas');
let c = canvas.getContext('2d');
let filename = "profile-photo";
let btnDownload = document.getElementById('download');
let reader = new FileReader();
let target = new Image();
let target2 = new Image();
let image = document.getElementById('image_perfil');
let image2 = document.getElementById('image_logo')

c.canvas.width = 1024;
c.canvas.height = 1024;

let download = function () {
    link = document.createElement('a');
    link.download = filename + '.png';
    link.href = document.getElementById('canvas').toDataURL()
    link.click();
}

let destroyInterval = () => {
    for (var i = 1; i < 99999; i++)
        window.clearInterval(i);
}

let load = () => {
    c.clearRect(0, 0, c.canvas.width, c.canvas.height);
    draw();
}

let draw = () => {
    //  made reponsive twibbon
    c.canvas.width = target.width;
    c.canvas.height = target.height;

    c.drawImage(target, 0, 0, target.width, target.height);
    c.drawImage(target2, 0, 0, target.width, target.height);
}

let enableButton = () => {
    let
}

let init = () => {
    run = setInterval(function () {
        load();
    }, 1000);
}
//IMAGEM SELECIONADA DA PASTA
let setTwibbon = () => {
     target2.src = 'images/IXER.png';
}

let imageReaderOnLoad = () => {
    reader.onload = (res) => {
        target.src = res.target.result.replace(/ +/g, "");
    }
}

let enableBtnDownload = () => {
    btnDownload.removeAttribute('disabled');
}

let generate = () => {

    if (image.files[0] === undefined)
        alert('Nenhuma imagem selecionada');

    else {

        destroyInterval();
        imageReaderOnLoad();
        setTwibbon();
        enableBtnDownload();
        // reader.readAsDataURL(image.files[0]);
        reader.readAsDataURL(image.files[0]);
        init();
    }
}

Só que só consigo o resultado que quero se na função setTwibbon é passado uma imagem dentro de uma pasta do projeto. Como fazer para que a imagem seja de forma upload? Clicar num input type file e essa imagem selecionada tomar o lugar do target2?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.