I would like to resize an image picked from the gallery. I've set targetHeight
and targetWidth
, but they seem to be ignored...
When picking an image from the camera, the setting allowEdit
gives me the possibility to crop the image, but not when the pic is coming from gallery.
I've tried some Crop plugins, but they don't match my needs or i can't implement them on ionic V1.
Do you have an idea on what can i change in my code to have a 200px x 200px square pic when choosing it from the gallery ?
// source_type is either 'camera' or 'gallery'
$scope.takePicture = function(source_type)
{
navigator.camera.getPicture(
function(uri){
$ionicPopup.alert({
title: 'New avatar',
template: 'Is uploading...'
});
// Create a root reference
var storageRef = firebase.storage().ref();
var newAvatar = "test.jpg";
var contentType = contentType || '';
var sliceSize = sliceSize || 512;
let byteCharacters = atob(uri);
let byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize)
{
let slice = byteCharacters.slice(offset, offset + sliceSize);
let byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++)
{
byteNumbers[i] = slice.charCodeAt(i);
}
let byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
var mountainImagesRef = storageRef.child("storage/pics/"+newAvatar);
var blob = new Blob(byteArrays);
mountainImagesRef.put(blob).then(function(snapshot)
{
console.log("Uploaded a base64 string!");
$scope.addNewAvatar(newAvatar);
});
},
function(){
$ionicPopup.alert({
title: 'Erreur',
template: 'Error'
});
},
{
quality: 70,
targetHeight: 200,
allowEdit: true,
targetWidth: 200,
destinationType: 0,
sourceType: source_type === 'gallery' ? 0 : 1,
mediaType: 0,
saveToPhotoAlbum: false
}
);
};