src/modules/jpeg_support.js
function (imgData) {
        var width, height, numcomponents;
        var blockLength = imgData.charCodeAt(4) * 256 + imgData.charCodeAt(5);
        var len = imgData.length;
        var result = { width: 0, height: 0, numcomponents: 1 };
        for (var i = 4; i < len; i += 2) {
            i += blockLength;
            if (markers.indexOf(imgData.charCodeAt(i + 1)) !== -1) {
                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);
                result = { width: width, height: height, numcomponents: numcomponents };
                break;
            } else {
                blockLength = imgData.charCodeAt(i + 2) * 256 + imgData.charCodeAt(i + 3);
            }
        }
        return result;
    }
function (imgData) {
        var width, height, numcomponents;
        var blockLength = imgData.charCodeAt(4) * 256 + imgData.charCodeAt(5);
        var len = imgData.length;
        var result = { width: 0, height: 0, numcomponents: 1 };
        for (var i = 4; i < len; i += 2) {
            i += blockLength;
            if (markers.indexOf(imgData.charCodeAt(i + 1)) !== -1) {
                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);
                result = { width: width, height: height, numcomponents: numcomponents };
                break;
            } else {
                blockLength = imgData.charCodeAt(i + 2) * 256 + imgData.charCodeAt(i + 3);
            }
        }
        return result;
    }
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