I compressed a png file using ImageOptim. I used the Zopfli as the method of compressing. ImageOptim guarantees that it's a lossless compression. Truly my png size has reduced, but how can i decompress it back to the original size?
I read about Zopfli compression, it said that it compresses png files using deflate algorithm. How can inflate/decompress the compressed png back to original file in java?
Zopli does not optimize the already compressed stream of PNG data. It works on decompressed image from scratch. So you can not undo the process. If you insist on getting the exact same result before the optimization you can decompress to bitmap and encode to PNG using the original algorithm, again.
A little more explanation: Let's simplistically say you need to compress the string "1111111111". A first lossless compression function which has a max buffer size of 5 bytes would output it as "5x1,5x1"(5 times 1 then 5 times 1), then a second implementation of the same algorithm which has a max buffer of 10 bytes outputs "10x1" which looks better. Both results are of course lossless, but most often you can not go to "5x1,5x1" from "10x1".
To make sure the compressions are really lossless you may simply decompress and compare uncompressed versions. In your case, decompress both original PNG and optimized PNG to bitmap and compare bitmaps.
No need to program;
Use ImageMagick to compare files
Lossless Compression:
Command:
Output:
A value of
0
shows zero difference, hence no loss.Lossy Compression:
Command:
Output: