question about using jpegtran for lossless compression of jpegs

Discussion in 'Digital Photography' started by ewaguespack@gmail.com, Oct 10, 2006.

  1. Guest

    first of all, sorry for the cross-posting, but I am not sure where to
    go for help with this...

    I have been using a freeware windows application that strips all non
    image info from a jpeg, here are the details:

    http://davidcrowell.com/jStrip/Default.aspx
    Features

    jStrip removes the following from JPEG files:

    * Comments (optionally)
    * EXIF Data (optionally)
    * JFIF Header (optionally)
    * Photoshop Image Resource Block (optionally)
    * ICC color profile
    * Adobe APP14 tag (optionally)
    * XMP data (optionally)
    * Extra bytes at end of file
    * Extra bytes or header at beginning of file
    * Extra bytes between JPEG blocks
    * Application-specific APPx blocks
    * Photoshop thumbnails
    * Any other unknown blocks in the JPEG files

    in attempting to come up with a solution that does all of the above in
    linux, I have played around with a couple of perl solutions, jhead,
    exiftool, and jpegtran.

    the best thing I have come up with so far is the following:
    #jpegtran -optimize -outfile $image $image

    or recursively:
    # find -type f -name "*.jpg" -exec jpegtran -optimize -copy none
    -outfile {} {} \;

    other options I played with were the following:
    # exiftool -all= $image
    # jhead -purejpg $image

    so, anyway to finally get to my point, the jpegtran (Linux) solution
    does everything that jstrip (windows) does, (and more: optimize,
    progressive) except remove the jfif header

    so the question is, how do I remove the jfif header in a scripted,
    recursive fashion in Linux.

    If I am successful at finding a solution with this, it will finally
    allow me to move completely to Linux.

    finally, if you know where a forum / mailing list is that would be more
    appropriate, please let me know.

    Thank you in advance.
     
    , Oct 10, 2006
    #1
    1. Advertising

  2. bugbear Guest

    wrote:
    >
    > so, anyway to finally get to my point, the jpegtran (Linux) solution
    > does everything that jstrip (windows) does, (and more: optimize,
    > progressive) except remove the jfif header


    jpegtran -copy none a.jpg b.jpg

    on my machine strips EXIF (and everything else :)
    perfectly.

    My jpeg version is libjpeg-6b-34

    Are you sure of your results?

    I'm checking for EXIF using
    Image-ExifTool-5.62

    BugBear
     
    bugbear, Oct 10, 2006
    #2
    1. Advertising

  3. Guest

    bugbear wrote:
    > wrote:
    > >
    > > so, anyway to finally get to my point, the jpegtran (Linux) solution
    > > does everything that jstrip (windows) does, (and more: optimize,
    > > progressive) except remove the jfif header

    >
    > jpegtran -copy none a.jpg b.jpg
    >
    > on my machine strips EXIF (and everything else :)
    > perfectly.
    >
    > My jpeg version is libjpeg-6b-34
    >
    > Are you sure of your results?
    >
    > I'm checking for EXIF using
    > Image-ExifTool-5.62
    >
    > BugBear


    well I am not an expert at jpeg file structure, but if you download
    that jstrip program and enable the optional "jfif header removal" your
    get a 18 byte (i believe) reduction in size beyond what jpegtran
    provided.
     
    , Oct 10, 2006
    #3
  4. wrote:
    > so the question is, how do I remove the jfif header in a scripted,
    > recursive fashion in Linux.


    I'm curious why you want to do this, as the header takes almost no space and
    without it a lot of software probably won't recognize the image. I don't
    know of any existing utility that'll strip the JFIF header, but this should
    do the trick:


    /* Strip JFIF headers from the JPEG image on stdin, and write
    the result to stdout. Won't work unmodified on Windows
    because of the text/binary problem. Not thoroughly tested. */

    #include <stdio.h>
    #include <stdlib.h>

    void fail(const char* msg)
    {
    fputs(msg, stderr);
    exit(1);
    }

    void copy_rest(FILE* f, FILE* g)
    {
    char buf[4096];
    int len;
    while ((len = fread(buf, 1, sizeof buf, f)) > 0) {
    if (fwrite(buf, 1, len, g) != len)
    fail("write error");
    }
    if (len < 0)
    fail("read error");
    }

    void strip_app0(FILE* f, FILE* g)
    {
    int a,b;
    a = getc(f); b = getc(f);
    if (a != 0xFF || b != 0xD8)
    fail("not a JPEG file");
    putc(a,g); putc(b,g);
    while (a = getc(f), b = getc(f), a == 0xFF && b == 0xE0) {
    a = getc(f); b = getc(f);
    if (a == EOF || b == EOF)
    fail("stop confusing me with weird test cases");
    fseek(f, a * 256 + b - 2, SEEK_CUR);
    }
    if (a != EOF) putc(a,g);
    if (b != EOF) putc(b,g);
    copy_rest(f,g);
    }

    int main()
    {
    strip_app0(stdin,stdout);
    return 0;
    }


    -- Ben
     
    Ben Rudiak-Gould, Oct 12, 2006
    #4
  5. bugbear Guest

    wrote:
    >
    > well I am not an expert at jpeg file structure, but if you download
    > that jstrip program and enable the optional "jfif header removal" your
    > get a 18 byte (i believe) reduction in size beyond what jpegtran
    > provided.
    >


    Apologies - I was reading "EXIF" and/or IPTC
    for jfif.

    (btw, jfif isn't technically a header, but comments
    in the JPEG stream, but I'm guessing you already knew that)

    BugBear
     
    bugbear, Oct 24, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC Dill

    batch lossless auto-rotate jpegs

    JC Dill, Mar 22, 2006, in forum: Digital Photography
    Replies:
    3
    Views:
    511
    jimbok
    Mar 22, 2006
  2. Sachin Garg

    'extra' lossless compression for camera raw images

    Sachin Garg, Mar 18, 2008, in forum: Digital Photography
    Replies:
    52
    Views:
    1,204
  3. Sachin Garg

    'extra' lossless compression for camera raw images

    Sachin Garg, Jul 5, 2008, in forum: Digital Photography
    Replies:
    12
    Views:
    637
    Sachin Garg
    Jul 8, 2008
  4. Sachin Garg

    Rawzor beta release (lossless raw compression)

    Sachin Garg, Sep 2, 2008, in forum: Digital Photography
    Replies:
    84
    Views:
    1,959
    Sachin Garg
    Sep 15, 2008
  5. Giuen
    Replies:
    0
    Views:
    1,250
    Giuen
    Sep 12, 2008
Loading...

Share This Page