question about using jpegtran for lossless compression of jpegs

question about using jpegtran for lossless compression of jpegs

Post by ewaguespac » Wed, 11 Oct 2006 09:10:23


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://www.yqcomputer.com/
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.
 
 
 

question about using jpegtran for lossless compression of jpegs

Post by bugbea » Wed, 11 Oct 2006 17:50:35


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

 
 
 

question about using jpegtran for lossless compression of jpegs

Post by ewaguespac » Wed, 11 Oct 2006 23:55:20


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.
 
 
 

question about using jpegtran for lossless compression of jpegs

Post by Ben Rudiak » Fri, 13 Oct 2006 21:21:59


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
 
 
 

question about using jpegtran for lossless compression of jpegs

Post by bugbea » Wed, 25 Oct 2006 18:55:25


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