Phonegap reduce image size

I have a phonegap application that has multiple input fields including textboxes/textareas/signatures/cad sketches/camera images. This data is uploaded to the server via an ajax post.

Problem:

When uploading the data the file is unreasonably large and takes a great deal of time to upload due to the images. When no photos are added the size is around 200kb - 400kb but with images the file has reached 60Mb and in terms of using an android device with a poor internet connection (Area with bad signal) this is unusable.

What I have tried:

I have used image compression in the camera options as seen in the below extract of code, however the challenge I am facing is that different devices with different camera specifications are utilized so if the device has a poor quality camera vs a device with a good quality camera image compression will take place regardless so the image quality will be terrible.

 var cameraOptions = {
                    destinationType: Camera.DestinationType.DATA_URL,
                    quality: 40,
                    encodingType: 0,
                };

Reference to the phonegap camera API and options:

http://docs.phonegap.com/en/2.0.0/cordova_camera_camera.md.html#Camera

From reading the below post I deduced that jpeg is the lightest format so used the endodingType of 0

PNG vs. GIF vs. JPEG vs. SVG - When best to use?

What we want to achieve:

Limiting the image size to maximum of 500kb per image and if its larger then than that compress it.

Answers:

Answer

I tried with different camera options and with the following I got file sizes of 4.5MB from an iPhone 5:

navigator.camera.getPicture(onSuccess, onFail, {
    destinationType : Camera.DestinationType.DATA_URL,
    sourceType : Camera.PictureSourceType.CAMERA,
    quality : 50,
    encodingType : Camera.EncodingType.JPEG
});

Only by adding the line

correctOrientation : true

File size reduced to ~500kB.

I don't have any explanation to why it should work this way, but I suggest you try it if the quality property doesn't seem to do anything.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.