Reputation: 251
I'm developping an mobile application with cordova and ionic and I would like to get the size of the image contained in a string without showing it (no img element in html). I have 2 problem, I've found a solution but with onload event and I don't use jQuery. Is there any working way with angular and ionic?
Upvotes: 2
Views: 5287
Reputation: 251
I found the solution :
Extract size from Image loaded
var width, height, myBase64 = "data:image/png;base64,R0lGODlhDwAPAKECAAAAzMzM...........yIQAAOw==";
var img = new Image();
img.src = myBase64;
img.addEventListener('load',function(){
width=img.width;
height=img.height;
});
With this way you don't need to use jQuery at all. It is pure JavaScript.
Upvotes: 3