/* gifsize.c - Don Yang (uguu.org) Reads GIF image from stdin, and writes width and height to stdout. http://en.wikipedia.org/wiki/Graphics_Interchange_Format 2013-05-05 */ #include int main(int argc, char **argv) { unsigned char header[10]; int width = 0, height = 0; if( fread(header, 10, 1, stdin) == 1 && (memcmp(header, "GIF87a", 6) == 0 || memcmp(header, "GIF89a", 6) == 0) ) { width = (header[7] << 8) | header[6]; height = (header[9] << 8) | header[8]; } printf("%d %d\n", width, height); return 0; }