First, resize the image into thumbnail-like size
2nd, store the image into targeted directory
This is achievable with Phonegap-image-resizer
$window.imageResizer.resizeImage(function(resizedImage) {
// Store image into local
$window.imageResizer.storeImage(function(response) { // cache
var filePath = response.filename,
pathOnly = filePath.substring(0, sourceFile.lastIndexOf('/')) + '/',
filename = filePath.split('/').pop().replace(/\#(.*?)$/, '').replace(/\?(.*?)$/, '');
// store file into targeted location here with
// cordova official File plugin
$cordovaFile.moveFile(pathOnly, filename, cordova.file.dataDirectory).then(function(success) {
console.log(success);
}, function(error) {
console.log(errir);
});
}, function(error) {
return error;
}, resizedImage.imageData, {
imageDataType: ImageResizer.IMAGE_DATA_TYPE_BASE64,
format: 'jpg',
filename: // new name,
directory: // location to store,
quality: 80
});
}, function(error) {
return error;
}, photo.url, 0.2, 0.2, {
imageDataType: ImageResizer.IMAGE_DATA_TYPE_URL,
resizeType: ImageResizer.RESIZE_TYPE_FACTOR,
format: 'jpg'
});
Two parts here:
TL;DR
1st step, $window.imageResizer.resizeImage will resize the image
2nd step, $window.imageResizer.storeImage store image
Cursory go through resizeImage.js to better understand how to utilise the code.
Reference: Converting Large Images to Base64Strings in Ionic Framework
Thank you, this article the most useful guid for using Cordova Resizer plugin
ReplyDelete