Start
   Blogaria
   Bored
   bsgen
   c-conf
   Cookies
   cycliclog
   Dialwhatever
   dnspb
   fch
   HammerServer
   jpeginfo
   kalk
   Lectures
   Microproxy
   msc
   Nasapics
   Off The Grid
   PGPkey
   Posters
   SafeEdit
   Simple listserv
   syscheck
   Wallpapers
   xml tools
Karel as an adult



jpeginfo

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

Legalese

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.

Instructions

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,
"\n"		 
"This is jpeginfo V" VER ", copyright (c) Karel Kubat <karel@kubat.nl>.\n" 
"Visit http://www.kubat.nl/pages/jpeginfo for downloads and information.\n"
"Usage: jpeginfo jpegfile(s)\n"
"Shows properties of the stated file(s). Use '-' for stdin.\n"
"\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,
		cinfo.num_components);
	switch (cinfo.jpeg_color_space) {
	case JCS_GRAYSCALE:
	    printf ("monochrome");
	    break;
	case JCS_RGB:
	    printf ("red/green/blue");
	    break;
	case JCS_YCbCr:
	    printf ("Y/Cb/Cr");
	    break;
	case JCS_CMYK:
	    printf ("C/M/Y/K");
	    break;
	case JCS_YCCK:
	    printf ("Y/Cb/Cr/K");
	    break;
	default:
	    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)\" $<

clean:
	rm -f jpeginfo jpeginfo.o .gdb_history

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

Warning

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... http://search.cpan.org/dist/Image-Info/lib/Image/Info.pm :-)
Thanks a bunch Ed! Sigh... Well, at least I got to do a bit of C programming again.