Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the various JPEG Extensions?

While working on a downloader, I've encountered the following with Python's mimetypes.guess_extension function:

In [2]: mimetypes.guess_extension('image/jpeg', strict=False)
Out[2]: '.jpe'

I knew that jpeg and jpg are valid JPEG extensions, but I didn't know about jpe. So looking at the wikipedia site did reveal the following:

The most common filename extensions for files employing JPEG compression are .jpg and .jpeg, though .jpe, .jfif and .jif are also used

Even more extensions I didn't know of.

So the main question: Why does JPEG have so many (valid) extensions associated with it?

On a related note I'd like to know why Python does return 'jpe' and not 'jpg' or 'jpeg' since I see these used the most.

like image 671
Luis Nell Avatar asked Jul 09 '12 13:07

Luis Nell


People also ask

What is the extension of JPEG?

JPEG files usually have a filename extension of .jpg or .jpeg . JPEG/JFIF supports a maximum image size of 65,535×65,535 pixels, hence up to 4 gigapixels for an aspect ratio of 1:1.

Is there any difference between JPG and JPEG?

2. Both Terms Mean the Same Thing. Remember when we discussed the term JPEG and how it stood for the Joint Photographic Experts Group? Well, you guessed it; both JPEG and JPG are abbreviations for that same ISO sub-committee.

Why are JPEG files used?

A JPEG is a standardised lossy compression mechanism for digital images. Digital cameras compress raw photographs as JPEG images to make the files smaller in size. It is the most common file format for photo storage. JPEGs became popular as they save more storage space compared to older formats such as Bitmap.


1 Answers

It appears mimetypes.guess_extension returns the first of all possible extensions:

def guess_extension(self, type, strict=True):
    # ...
    extensions = self.guess_all_extensions(type, strict)
    if not extensions:
        return None
    return extensions[0]

So you'll get whichever is first in the list returned by mimetypes.guess_all_extensions, which turns out to be:

>>> mimetypes.guess_all_extensions('image/jpeg', strict=False)
['.jpe', '.jpg', '.jpeg']

My guess as to why .jpe is also valid:

In DOS and early Windows versions filenames could only have 8 characters and 3 characters for the extension (see the article 8.3 filename on Wikipedia for more info). It could be that they abbreviated JPEG to .JPE or .jpe - which is why we now have .jpe, .jpeg and .jpg.

It's indeed true that .jpeg and .jpg are more common.

like image 91
Simeon Visser Avatar answered Oct 21 '22 01:10

Simeon Visser