Convert the image returned from the Cordova Contacts Plugin to base64 (iOS)


After I’ve retrieved a contact image from the Cordova Contacts Plugin on iOS, I would like to encode it to base64. Here is my code to do so:

var c = document.createElement("canvas");
var ctx = c.getContext("2d");
var img = document.createElement("img");
img.src = "file:///" +[0].value;
ctx.drawImage(img, 100, 100);

However, every time I try this, the console outputs an empty image. What am I doing wrong?

How to save a contact to iOS address book with an image?

your need to wait until the image is ready and loaded
add a listener to img.onload.

img.onload = function () {
  ctx.drawImage(img, 100, 100);
img.src = ".....";


Hm, it still isn’t working. The image logged to the console is the same.


Any ideas on this? For the life of me I cannot figure out how to do it.


Look at this example:

there the canvas is already in the dom, but you can create it before


I’ll check it out. Thanks.