How to check low resolution photos when using cordova camera plugin?

I have the following code. This pretty much works for the most part. I would like to catch people with shitty cameras, and some of them warn that their pictures will stink. (using version "cordova-plugin-camera" version 2.3.0)

var cameraOpts = { quality: 100, // destinationType: Camera.DestinationType.FILE_URI, destinationType: Camera.DestinationType.DATA_URL, sourceType: $scope.sourceType, allowEdit: false, encodingType: Camera.EncodingType.JPEG, // popoverOptions: CameraPopoverOptions, targetWidth: 186, targetHeight: 1024, saveToPhotoAlbum: true, correctOrientation: true }; $cordovaCamera.getPicture(cameraOpts).then(function(imageData) { var image = "data:image/jpeg;base64," + imageData; $scope.setUpImage(index,image); }, function(err) { // error $scope.showAlert('Warning!', 'Camera cancelled!'); }); 

Any ideas would be appreciated. I am looking for a way to catch low resolution photos and tell the user.

+6
source share
2 answers

the corora camera plugin provides the quality of the camera option, but it does not provide any resolution information (default 100) ( enter the description link here )

0
source

You should create an Image object (this is the standard HTML5 API)

The corresponding snippet is copied from this answer:

HTML5 - how to get image size

From the plugin document: "The image is passed to the success callback as a Base64 encoded string or as a URI for the image file"

If you choose base64 format in the camera plugin, the data URI will be

 'data:image/jpg;base64,' + imageData 

However, the doc plugin recommends a file format that will return a file URL that you can assign directly to your image.src

 var image = new Image(); image.onload = function(evt) { var width = this.width; var height = this.height; alert (width); // will produce something like 198 }; //here is where you pass the camera data to create the image image.src = imageData; 

As you can see, the method is asynchronous, you can wrap it in Promise or emit an event when the image has been loaded and you have width x height

0
source

Source: https://habr.com/ru/post/1015308/