How to get the image size with Cordova?

Asked

Viewed 20 times

1

I have the following function, and I need to get the size of the image to validate, as it is not allowed to upload an image larger than a certain size. I can’t catch with normal JS because I don’t use one FileUplod, rather than by navigator.camera.getPicture. I tried to use the functions reported in the documentation but I couldn’t fit it with the existing code. I don’t know if you can get the size so that I get the image using the getPicture

function PerfilEscolherFoto() {
    var srcType = Camera.PictureSourceType.SAVEDPHOTOALBUM;
    var options = {
        // Some common settings are 20, 50, and 100
        quality: 100,
        destinationType: Camera.DestinationType.FILE_URI,
        // In this app, dynamically set the picture source, Camera or photo gallery
        sourceType: srcType,
        encodingType: Camera.EncodingType.JPEG,
        mediaType: Camera.MediaType.PICTURE,
        allowEdit: true,
        correctOrientation: true  //Corrects Android orientation quirks
    }
    navigator.camera.getPicture(function cameraSuccess(imageUri) {
        onSuccess1(imageUri);console.log(imageUri)
    }, function cameraError(error) {
        onFail1();
    }, options);

    function onSuccess1(imageData) {
        
        if (imageData.indexOf("?")=="-1"){
            imageData3 = imageData;

        } else {
            imageData2 = imageData.split('?');
            imageData3 = imageData2[0];
        }

        $(".FotoEditarAtleta").css("background", "url('"+ imageData3 +"?"+ Math.random() +"') no-repeat center").css('background-size', 'contain').css({ transform : 'rotate(0deg)' });
        $("#foto").val(imageData3);
    }

    function onFail1(message) {
        //alert('Erro ao selecionar imagem, tente novamente');
    }
}

  • See if this reply from Soen can help you: https://stackoverflow.com/a/11999301/2570426

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.