Off The Grid
   Simple listserv
   xml tools
Karel as an adult


jpeginfo is a small tool that shows information about jpegs. Given a list of jpeg file arguments, it shows the image sizes, the number of components in each image, and the color scheme.

It's a really small tool of which I'm sure that countless other exist. I was too lazy to search for something suitable, so I just cooked it myself. As an example, given a command line like jpeginfo *.jpg it might show:

xroads2.jpg: 1203 x 800 / 3 components / Y/Cb/Cr
xroads4.jpg: 1203 x 800 / 3 components / Y/Cb/Cr


It seems a bit overdone to include this section for such a trivial tool, but here goes. jpeginfo is distributed as-is, without warranty or anything. Basically you are free to use it and abuse it as you wish. However, if you add functionality, drop me a note; I'd like to hear about it.


To get it yourself, copy the two listings below as jpeginfo.c and as Makefile. Then hit make install. You will need libjpeg on your system, including the header file jpeglib.h. This is often called package libjpeg-devel or similar (so you'll need not just the runtime package, but the development files as well).

The step make install puts the binary program jpeginfo into /usr/local/bin. Edit the Makefile if you want a different location.

The Files

Here is jpeginfo.c:
 * jpeginfo.c
 * Part of jpeginfo, a small tool to show properties of jpeg images.
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <jpeglib.h>

int main (int argc, char **argv) {
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    int i;
    FILE *inf;
    /* Verify argument list */
    if (argc < 2) {
	fprintf (stderr,
"This is jpeginfo V" VER ", copyright (c) Karel Kubat <>.\n" 
"Visit for downloads and information.\n"
"Usage: jpeginfo jpegfile(s)\n"
"Shows properties of the stated file(s). Use '-' for stdin.\n"
	exit (1);

    /* Process all files. */
    for (i = 1; i < argc; i++) {
	cinfo.err = jpeg_std_error (&jerr);
	jpeg_create_decompress (&cinfo);

	printf ("%s: ", argv[i]);
        fflush (stdout);
	if (!strcmp (argv[i], "-"))
	    jpeg_stdio_src (&cinfo, stdin);
	else if (! (inf = fopen (argv[i], "r")) ) {
	    fprintf (stderr, "Cannot read %s: %s\n", argv[i], strerror(errno));
	    exit (1);
	} else
	    jpeg_stdio_src (&cinfo, inf);

	jpeg_read_header (&cinfo, TRUE);

	printf ("%u x %u / %d components / ",
		cinfo.image_width, cinfo.image_height,
	switch (cinfo.jpeg_color_space) {
	    printf ("monochrome");
	case JCS_RGB:
	    printf ("red/green/blue");
	case JCS_YCbCr:
	    printf ("Y/Cb/Cr");
	case JCS_CMYK:
	    printf ("C/M/Y/K");
	case JCS_YCCK:
	    printf ("Y/Cb/Cr/K");
	    printf ("unknown");
	putchar ('\n');
	jpeg_destroy_decompress (&cinfo);
	if (strcmp (argv[i], "-"))
	    fclose (inf);

    /* All done */
    return (0);
And here is the Makefile:
# Central Makefile for jpeginfo
# -----------------------------

BINDIR = /usr/local/bin
VER = 1.00

jpeginfo: jpeginfo.o
	$(CC) -o $@ -L/opt/local/lib -ljpeg $<

jpeginfo.o: jpeginfo.c Makefile
	$(CC) -c -g -Wall -W -o $@ -DVER=\"$(VER)\" $<

	rm -f jpeginfo jpeginfo.o .gdb_history

install: jpeginfo
	mkdir -p $(BINDIR)
	install -s jpeginfo $(BINDIR)/jpeginfo


Aah this makes my day. Eddie N. wrote me after reading this page:
Why don't you stop writing those weird little C programs of yours... :-)
Thanks a bunch Ed! Sigh... Well, at least I got to do a bit of C programming again.