#include <stdio.h>
#include <unistd.h>
#include "jpeg-6b/jpeglib.h"

int imgFjpeg_size(char *filename, int *width, int *height)
{
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE *infile;

    cinfo.err = jpeg_std_error(&jerr);
    jpeg_create_decompress(&cinfo);

    if ((infile = fopen(filename, "rb")) == NULL) {
        jpeg_destroy_decompress(&cinfo);
        return -1;
    }
    jpeg_stdio_src(&cinfo, infile);
    jpeg_read_header(&cinfo, TRUE);

    fclose(infile);

    *width = cinfo.image_width;
    *height = cinfo.image_height;

    jpeg_destroy_decompress(&cinfo);

    return 0;
}
