Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When a web server returns a JPEG image (mime type image/jpeg), how is that encoded?

If you make an HTTP request to a web server, and it returns a response of type image/jpeg, how is the binary data actually encoded? Is it the original byte-level content of the image that goes across the wire, or some character-based representation of it (e.g. base64)?

like image 379
Gary McGill Avatar asked Sep 09 '12 00:09

Gary McGill


People also ask

How is a JPEG encoded?

The JPEG compression is a block based compression. The data reduction is done by the subsampling of the color information, the quantization of the DCT-coefficients and the Huffman-Coding (reorder and coding). The user can control the amount of image quality loss due to the data reduction by setting (or chose presets).

Are JPEG images valid?

No, image/jpg is not the same as image/jpeg . You should use image/jpeg . Only image/jpeg is recognised as the actual mime type for JPEG files.

What does jpg file mean?

jpg or . jpeg) stands for "Joint Photographic Experts Group", which is the name of the group who created the JPEG standard.


2 Answers

The encoded transfered data is specified by the Content-Encoding HTTP response header (see HTTP 1.1 specifications in RFC2616 section 14.11 and 3.5). If present, it can be either gzip, compress, or deflate compressed data (no others are defined in HTTP 1.1). If not, the data is in original encoding based on the Content-Type HTTP response header (the MIME type). The Content-Encoding is determined by the Accept-Encoding HTTP request header value and whether the web server support requested encoding.

In your case, if the Content-Encoding HTTP response header is absent, the data is exactly the same as the file contents. Otherwise, it's compressed with the specified encoding. e.g.: GZip or Deflate.

like image 132
Jay Avatar answered Oct 27 '22 05:10

Jay


The original bytes are sent across the wire.

(With a bit of setup, you can confirm this with Wireshark, tcp_dump et al.)

Note that most servers are configured not to compress JPEGs, but that text data is generally sent compressed.

like image 37
ron rothman Avatar answered Oct 27 '22 07:10

ron rothman