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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With