Main Page | Report this Page
Science Forum Index  »  Compression Forum  »  JPEG (de/reverse)compression PHP GD library...
Page 1 of 1    

JPEG (de/reverse)compression PHP GD library...

Author Message
blu3fire...
Posted: Thu Oct 15, 2009 10:07 am
Guest
Hello.
I'm wondering if it's possible to recompress a file back to the
original state. I mean:
1.I have a valid JPEG file (nicepic.jpg).
2. Using PHP GD function I load that file using imagecreatefromjpeg()
function (it cuts MIME/EXIF data like author, comments, etc. and
converts it to the RGB)
3. Using imegejpeg() function with settled parameters the image is
being converted back to the JPEG format and saved to the file
(otherpic.jpg).

The images nicepic.jpg and otherpic.jpg are very different (besides
the markers like Huffman tables, SOS, JFIF, Quantization)... I
mean ... they're binary different (visually the same).

There is my question... how to get reverse compression/decompression
of file otherpic.jpg back to the original state (nicepic.jpg) before
all steps I described above?

PS
GD library uses The Independent JPEG Group's jpeglib.
 
blu3fire...
Posted: Fri Oct 16, 2009 12:57 am
Guest
On 16 Paź, 09:36, Thomas Richter <t... at (no spam) math.tu-berlin.de> wrote:
[quote:9141defeec]blu3fire schrieb:





Hello.
I'm wondering if it's possible to recompress a file back to the
original state. I mean:
1.I have a valid JPEG file (nicepic.jpg).
2. Using PHP GD function I load that file using imagecreatefromjpeg()
function (it cuts MIME/EXIF data like author, comments, etc. and
converts it to the RGB)
3. Using imegejpeg() function with settled parameters the image is
being converted back to the JPEG format and saved to the file
(otherpic.jpg).

The images nicepic.jpg and otherpic.jpg are very different (besides
the markers like Huffman tables, SOS, JFIF, Quantization)... I
mean ... they're binary different (visually the same).

There is my question... how to get reverse compression/decompression
of file otherpic.jpg back to the original state (nicepic.jpg) before
all steps I described above?

Not with the IJG software, at least. If you really need that, you'd need
to write your own JPEG implementation. You would need to record the
order in which the markers are written in the original file, all the
modes, all the Huffman tables, and you need to have a DCT that is 1:1
(losslessy) invertible to the precision defined by the quantizer, which
might be again not so easy.

The important point is probably: The JPEG standard doesn't define the
DCT up to a point where numerically identical results can be obtained. I
do have such a proposal on the table (for an integer DCT), but I'll
doubt somehow that it would be accepted given that there are already
many "incompatible" DCT implementations around.

Even with other standards, recompression to a binary identical file is
hard, but probably not as hard as for JPEG. In JPEG 2000, if you are
really really careful, the lossless path would probably allow you that.
In JPEG-XR, it would probably allow you that if you're careful.

So long,
        Thomas
[/quote:9141defeec]
Thank you Thomas for your professional reply. But another question
came out... Is possible to foresee (more or less accurate) the binary
result of JPEG after described conversions (through IJG)? I mean... I
want to get specific byets sequence after conversion... and need to
know how input file should looks like to get that sequence of bytes.

blu3fire
 
Thomas Richter...
Posted: Fri Oct 16, 2009 1:36 am
Guest
blu3fire schrieb:
[quote:048b8e2de7]Hello.
I'm wondering if it's possible to recompress a file back to the
original state. I mean:
1.I have a valid JPEG file (nicepic.jpg).
2. Using PHP GD function I load that file using imagecreatefromjpeg()
function (it cuts MIME/EXIF data like author, comments, etc. and
converts it to the RGB)
3. Using imegejpeg() function with settled parameters the image is
being converted back to the JPEG format and saved to the file
(otherpic.jpg).

The images nicepic.jpg and otherpic.jpg are very different (besides
the markers like Huffman tables, SOS, JFIF, Quantization)... I
mean ... they're binary different (visually the same).

There is my question... how to get reverse compression/decompression
of file otherpic.jpg back to the original state (nicepic.jpg) before
all steps I described above?
[/quote:048b8e2de7]
Not with the IJG software, at least. If you really need that, you'd need
to write your own JPEG implementation. You would need to record the
order in which the markers are written in the original file, all the
modes, all the Huffman tables, and you need to have a DCT that is 1:1
(losslessy) invertible to the precision defined by the quantizer, which
might be again not so easy.

The important point is probably: The JPEG standard doesn't define the
DCT up to a point where numerically identical results can be obtained. I
do have such a proposal on the table (for an integer DCT), but I'll
doubt somehow that it would be accepted given that there are already
many "incompatible" DCT implementations around.

Even with other standards, recompression to a binary identical file is
hard, but probably not as hard as for JPEG. In JPEG 2000, if you are
really really careful, the lossless path would probably allow you that.
In JPEG-XR, it would probably allow you that if you're careful.

So long,
Thomas
 
blu3fire...
Posted: Fri Oct 16, 2009 1:39 am
Guest
Thnaks for the info.

blu3fire
 
Thomas Richter...
Posted: Fri Oct 16, 2009 5:15 am
Guest
blu3fire schrieb:

[quote:d0bc1acdf2]Thank you Thomas for your professional reply. But another question
came out... Is possible to foresee (more or less accurate) the binary
result of JPEG after described conversions (through IJG)? I mean... I
want to get specific byets sequence after conversion... and need to
know how input file should looks like to get that sequence of bytes.
[/quote:d0bc1acdf2]
Not really, or rather: The shortest way is just to feed the IJG with a
given sequence and then observe the output. If you need a specific byte
sequence, I would rather drill up IJG to create such a sequence.

So long,
Thomas
 
paul van den berg...
Posted: Fri Oct 16, 2009 1:51 pm
Guest
On Thu, 15 Oct 2009 13:07:08 -0700 (PDT)
blu3fire <absolute.admin at (no spam) gmail.com> wrote:

[quote:a5166d885a]Hello.
I'm wondering if it's possible to recompress a file back to the
original state. I mean:
1.I have a valid JPEG file (nicepic.jpg).
2. Using PHP GD function I load that file using imagecreatefromjpeg()
function (it cuts MIME/EXIF data like author, comments, etc. and
converts it to the RGB)
3. Using imegejpeg() function with settled parameters the image is
being converted back to the JPEG format and saved to the file
(otherpic.jpg).

The images nicepic.jpg and otherpic.jpg are very different (besides
the markers like Huffman tables, SOS, JFIF, Quantization)... I
mean ... they're binary different (visually the same).

There is my question... how to get reverse compression/decompression
of file otherpic.jpg back to the original state (nicepic.jpg) before
all steps I described above?

Since jpeg is a lossy compression, you cannot reverse the compression.[/quote:a5166d885a]
If you compress a decompressed jpeg image, you compress something that
differs from the original image, so you you get another jpeg image.

If all you want to do is cutting meta information, use jpegtran (part
of IJG code):
jpegtran -copy none nicepic.jpg > otherpic.jpg
cuts MIME/EXIF data and saves original jpeg content.

Regards, Paul
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sat Dec 05, 2009 5:36 pm