Seguimi in Twitter Seguimi in Facebook Seguimi in Pinterest Seguimi in LinkedIn Seguimi in Google+ Seguimi  in Stumbleupon seguimi  in instagram Sottoscrivi il feed
Blender, graphic, software, open source, Linux LibreOffice, open source, openoffice Gimp, graphic, software, open source, Linux kernel, Linux, software, open source Linux, distributions, Ubuntu, Linux Mint, Fedora, Mandriva Jamin, gpl, library, open source matroska, multimedia, container, linux pcman, file manager, linux LuninuX, distribition, Linux, open source Linux, infographic, history

Saturday, April 20, 2013

Jpeginfo is a command line tool used to generate informative listings of JPEG files, and also to check JPEG files for errors

Jpeginfo_1Jpeginfo 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

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


jpeginfo_8h__dep__incl);
    }

    /* 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
    

Custom Search
 
If you liked this article, subscribe to the feed by clicking the image below to keep informed about new contents of the blog:

No comments:

Recent Posts

Linux News

My Blog List

BlogESfera Directorio de Blogs Hispanos - Agrega tu Blog BlogItalia.it - La directory italiana dei blog Il Bloggatore Find the best blogs at Blogs.com. AddThis Social Bookmark Button page counter Mi Ping en TotalPing.com Subscribe using FreeMyFeed