/* pngsize.c - Don Yang (uguu.org) Reads PNG image from stdin, and writes width and height to stdout. http://libpng.org/pub/png/spec/iso/ 2013-04-20 */ #include #include int main(int argc, char **argv) { unsigned char expected_header[8] = {137, 80, 78, 71, 13, 10, 26, 10}; unsigned char header[24]; unsigned int width = 0, height = 0; if( fread(header, 24, 1, stdin) == 1 && memcmp(expected_header, header, sizeof(expected_header)) == 0 ) { width = (header[16] << 24) | (header[17] << 16) | (header[18] << 8) | header[19]; height = (header[20] << 24) | (header[21] << 16) | (header[22] << 8) | header[23]; } printf("%u %u\n", width, height); return 0; }