JPEG SUPPORT
 takes a string imgData containing the raw bytes of a jpeg image and returns [width, height] Algorithm from: http://www.64lines.com/jpeg-width-height
function getJpegSize(imgData) {

    var width, height, numcomponents; // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00

    if (getImageFileTypeByImageData(imgData) !== 'JPEG') {
      throw new Error('getJpegSize requires a binary string jpeg file');
    }

    var blockLength = imgData.charCodeAt(4) * 256 + imgData.charCodeAt(5);
    var i = 4,
        len = imgData.length;

    while (i < len) {
      i += blockLength;

      if (imgData.charCodeAt(i) !== 0xff) {
        throw new Error('getJpegSize could not find the size of the image');
      }

      if (imgData.charCodeAt(i + 1) === 0xc0 || //(SOF) Huffman  - Baseline DCT
      imgData.charCodeAt(i + 1) === 0xc1 || //(SOF) Huffman  - Extended sequential DCT
      imgData.charCodeAt(i + 1) === 0xc2 || // Progressive DCT (SOF2)
      imgData.charCodeAt(i + 1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
      imgData.charCodeAt(i + 1) === 0xc4 || // Differential sequential DCT (SOF5)
      imgData.charCodeAt(i + 1) === 0xc5 || // Differential progressive DCT (SOF6)
      imgData.charCodeAt(i + 1) === 0xc6 || // Differential spatial (SOF7)
      imgData.charCodeAt(i + 1) === 0xc7) {
        height = imgData.charCodeAt(i + 5) * 256 + imgData.charCodeAt(i + 6);
        width = imgData.charCodeAt(i + 7) * 256 + imgData.charCodeAt(i + 8);
        numcomponents = imgData.charCodeAt(i + 9);
        return [width, height, numcomponents];
      } else {
        i += 2;
        blockLength = imgData.charCodeAt(i) * 256 + imgData.charCodeAt(i + 1);
      }
    }
  }