0

In my android application, I have to show the images in thumbnail view with reduced size(100 KB) instead of showing it with original size(1 MB). It helps to improve the performance of my application.

How to implement this compression functionality using Ionic/ Cordova. Could you please provide some suggestion to implement this functionality.

BALA MURUGAN
  • 1,825
  • 3
  • 16
  • 17

1 Answers1

1

Try this. It should work. But instead of image tag use canvas tag. Put this code in your javascript function for loading image. It compress your image to your desired dimensions.

img = new Image();
img.src = 'example.png'; // your file

img.onload = function(){
var canvas = document.getElementById('outputImage'); // id of your canvas
var ctx = canvas.getContext('2d');
canvas.width=400 // your dimensions
canvas.height=300
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
};
Shahbaz Hashmi
  • 2,631
  • 2
  • 26
  • 49