Skip to content

Instantly share code, notes, and snippets.

@Uriel29
Last active June 30, 2021 01:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uriel29/675faf3ca6e83c01e6ea to your computer and use it in GitHub Desktop.
Save Uriel29/675faf3ca6e83c01e6ea to your computer and use it in GitHub Desktop.
Verificar dimensões de imagem antes do Upload com Jquery. O JS vê o tamanho das imagens antes do Upload, avisa o usuário e desabilita o botão submit!
//Coloca a biblioteca Jquery no seu HTML.
jQuery("#img_principal").change(function() { //campo de imagem
var fr = new FileReader;
fr.onload = function() {
var img = new Image;
img.onload = function() {
if (img.width < 1400 && this.height < 800) {
jQuery('.aviso').append("<h2>Sua imagem é menor que 1400px de largura por 800px de altura </ br> use outra imagem</h2>");
jQuery("#submit").attr("disabled", true); //Desabilita o botão sumbit
} else {
jQuery('.aviso').remove(); //remove a DIV aviso
jQuery('.aviso').append("<h3> Sua imagem tem as dimensões corretas</h3>"); //add outra mensagem
jQuery("#submit").removeAttr("disabled"); // Abilita o botão submit
}
};
img.src = fr.result;
};
fr.readAsDataURL(this.files[0]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment