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 getJpegSizeFromBytes(data) {
    var hdr = data[0] << 8 | data[1];
    if (hdr !== 0xFFD8) throw new Error('Supplied data is not a JPEG');
    var len = data.length,
        block = (data[4] << 8) + data[5],
        pos = 4,
        bytes,
        width,
        height,
        numcomponents;

    while (pos < len) {
      pos += block;
      bytes = readBytes(data, pos);
      block = (bytes[2] << 8) + bytes[3];

      if ((bytes[1] === 0xC0 || bytes[1] === 0xC2) && bytes[0] === 0xFF && block > 7) {
        bytes = readBytes(data, pos + 5);
        width = (bytes[2] << 8) + bytes[3];
        height = (bytes[0] << 8) + bytes[1];
        numcomponents = bytes[4];
        return {
          width: width,
          height: height,
          numcomponents: numcomponents
        };
      }

      pos += 2;
    }

    throw new Error('getJpegSizeFromBytes could not find the size of the image');
  }