Jump to content

[js] Dimension imagen file input


Recommended Posts

Manes cortita, necesito validar las dimensiones de una imagen de un file input con js, en estos momentos lo estoy haciendo con ajax, pero me gustaría hacerlo en js puro para no tener que cargar la imagen, se que el DOM no puede acceder a el, pero ¿Hay un truquito o hack por ahí para lograrlo?

 

Só no más, saluditos

Link to comment
Share on other sites

Podrías usar algo como esto:

$('#tuFileInput').change(function() {    
    var fr = new FileReader;    
    fr.onload = function() {
        var img = new Image;        
        img.onload = function() {
            alert(img.width,mg.height);
        };        
        img.src = fr.result;
    };    
    fr.readAsDataURL(this.files[0]);    
});

Salutes :notonto:

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...