COMPRESS AN IMAGE FILE

how can we compress an IMAGE file from camera and store it store it in our DB.
To Compress an image file, which is been taken by Native Camera, following attribute is been used :

quality : It compresses the image and reduces the size of the image.Its value ranges from 1-100, where 100 means best quality image.

Example

Code: Select all

var jsonobj = {
        targetWidth: "200", 
        targetHeight: "200",
        crop: "Y",
        flash: "N",
        action: "base64_Save",
        fileName: imageNumber.toString(),
        quality: "50",
        encodingType: "JPG",
        sourceType: "Camera",
        openNativeCamera: "Y",
        fileOverwrite: "N"
    };
    apz.ns.openCamera(jsonobj);
To Insert Compressed Image in DB, we are supposed to use SQL Storage plugin of Appzillon

The storage plugin helps to do the following in the SQLite database available on the mobile device:

• Create a database
• Create tables in the database created
• Insert data into the tables in the database
• Select data from database
• Delete data from database.
Sir,

How can we convert an encoded IMAGE base 64 to IMAGE.
To get base64 encode image from Appzillon's camera plugin, please pass action as base64, after image is been taken, it will return encoded base 64 string in encodedImage in success call back , and that base 64 can displayed in HTML Image using src

Example :

To launch camera and get base64 string in success call back :

Code: Select all

var jsonobj = {
"zoomLevel": "20", 
"targetWidth": "200",
"targetHeight":"200",
"crop": "Y",//Y or N 
"flash": "N",
"action": "base64", 
"fileName": “Sample”,
"quality" : "50",
"encodingType" : "JPG",
"sourceType":"camera"   // photo
};
jsonobj.id = "CAMERA_ID";
    	jsonobj.callBack = cameraCallback;
   	apz.ns.openCamera(jsonobj);
To Display Image in HTML, in success callback :

Code: Select all

cameraCallback = function(pjson){
if(pjson.status){
document.getElementById("loadImage").src = "data:image/jpg;base64," + pjson.encodedImage;
}else{
alert("Failure");
}
}
In the same manner, if are retrieving image base 64 from database we can display it in HTML.