2

I'm using 14.04.1 LTS (server), I have installed the following: libjpeg8 libjpeg62 libjpeg-turbo8 libjpeg-progs libjpeg-turbo-progs

The image file in question returns this with the file command (I split into two lines):

$ file image.jpg
image.jpg JPEG image data, JFIF standard 1.01, 
comment: "CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100"

When I run cjpeg image.jpg I get the following error:

Unrecognized input file format --- perhaps you need -targa

Following the advice, I run cjpeg -targa image.jpg:

Invalid or unsupported Targa file

Searching google brought up a lot of source code files for various packages that call cjpeg and had bits of the error message in question spread throughout the file but nothing referenced the same error I am getting.

3
  • 1
    Can you upload the image somewhere so we can see it? You don't have to, it'll just make this fix easier.
    – Kaz Wolfe
    Oct 20, 2014 at 3:53
  • It is this image from unsplash.com Oct 21, 2014 at 14:40
  • See atmaish's comment below for jpegtran command.
    – nu everest
    Dec 22, 2015 at 19:42

1 Answer 1

2
+50

You get this error simply because you tried to compress an unsupported file (such as a JPG file), from the cjpeg man page:

cjpeg compresses the named image file, or the standard input if no file is named, and produces a JPEG/JFIF file on the standard output. The currently supported input file formats are: PPM (PBMPLUS color format), PGM (PBMPLUS gray-scale format), BMP, Targa, and RLE (Utah Raster Toolkit format). (RLE is supported only if the URT library is available.)

When I try to compress a JPG file I also get the same error:

$ cjpeg foo.jpg
Unrecognized input file format --- perhaps you need -targa

Actually this is the default error message, see cjpeg.c

  switch (c) {
#ifdef BMP_SUPPORTED
  case 'B':
    return jinit_read_bmp(cinfo);
#endif
#ifdef GIF_SUPPORTED
  case 'G':
    return jinit_read_gif(cinfo);
#endif
#ifdef PPM_SUPPORTED
  case 'P':
    return jinit_read_ppm(cinfo);
#endif
#ifdef RLE_SUPPORTED
  case 'R':
    return jinit_read_rle(cinfo);
#endif
#ifdef TARGA_SUPPORTED
  case 0x00:
    return jinit_read_targa(cinfo);
#endif
  default:
    ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);
    break;
  }

JERR_UNKNOWN_FORMAT is defined in cderror.h:

#ifdef TARGA_SUPPORTED
JMESSAGE(JERR_UNKNOWN_FORMAT,
     "Unrecognized input file format --- perhaps you need -targa")

Source: http://www.ijg.org/

6
  • So I would need to do a file conversion first? I assumed JPG would be compatible with cjpeg. Oct 21, 2014 at 14:38
  • 1
    @Brian: your image.jpg is already compressed. Converting this file to another compatible format and re-compress with cjpeg would result in a quality loss. Oct 21, 2014 at 14:42
  • @Brian: If your goal was to reduce the size of the jpg file, you can use this kind of command: convert unsplash_522ee1a4293f8_1.JPG -resize 50% image2.jpg. I hope I answered your original question Oct 21, 2014 at 14:53
  • You did answer it, it was a bad file format. Thank you for the succinct answer. Oct 21, 2014 at 14:54
  • 2
    Awesome! Thanks @SylvainPineau. Like you pointed out, I was using cjpeg to compress a jpeg. For a lossless optimization, I got around by using jpegtran which is present in the same package. Here's what I used: jpegtran -copy none -optimize -progressive old.jpeg > new.jpeg. Note that -copy none would strip the metadata from the image and -optimize would optimize the Huffman tables and improve compression.
    – atmaish
    Oct 21, 2014 at 18:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .