What is facebook's image compression algorithm? For a project I'm working on (master thesis), I need to figure out what is facebook's image compression algorithm.
The goal: to be able to mimic facebook's image compression locally (using python).
The images I use have the following exif: Image exif (Q = 90)
After facebook compression, I have the following exif : Compressed image exif
Note: If the images I uploaded with the link seem unavailable, please refresh the page! :)
After searching for a while, I could not find a recent and clear answer to my question.
I tried to run the compressed image through ImageMagick's identify. It tells me that it is a JPEG compression (DCT progressive + Huffman) with a quality of 85. But when I try to do my own compression using python, the result is not the same.
Here is my code:
from PIL import Image
img = Image.open('original.jpg')
img.save('output.jpg', optimize=True, quality=85, progressive=True)

Do you have any ideas or resources that could help me? I'm running out of ideas.
Thank you!
If you have access to the bitstream, you should be able to figure out which codec they are using.
Assuming that it is good old jpeg, possibly with a tweaked encoder implementation, I would parse the stream using JPEGSnoop to learn as much as possible. It can even try to match «known»
encoders:
https://www.impulseadventure.com/photo/jpeg-snoop.html
If you can upload uncompressed bmp images to facebook and observe the first-generation compressed jpeg, you might learn even more as you have a reference.
Reverse engineering an encoder black box like this may be tedious unless they went with a plain vanilla implementation.
JPEG is actually a flexible standard, and «quality=85» is a simplified way of expressing how 8x8 DCT coefficients of luma (and chroma) are quantified. Sniffing the stream will allow you to read out those 2x64 quantization scalings, and also (if any) chroma subsampling, and (unlikely) non-bt601 color primary matrixing. An encoder is allowed to set any (small) dct coeff to zero if it likes (in the interest of smaller files), besides the regular quantization. Also, the encoder may use non-standard huffman tables but that should affect the bitstream not pixels.