Image functionality ported from pdf.js
function getImageIndex(images) {
    var imageIndex = 0;

    if (images) {
      // this is NOT the first time this method is ran on this instance of jsPDF object.
      imageIndex = Object.keys ? Object.keys(images).length : function (o) {
        var i = 0;

        for (var e in o) {
          if (o.hasOwnProperty(e)) {
            i++;
          }
        }

        return i;
      }(images);
    }

    return imageIndex;
  }