为什么各种JPEG扩展? [英] Why the various JPEG Extensions?
问题描述
在处理下载程序时,我遇到了以下Python的 mimetypes.guess_extension
函数:
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'
我知道 jpeg 和 jpg 是有效的JPEG扩展,但我没有了解 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:
使用JPEG压缩的文件最常见的文件扩展名是.jpg和.jpeg,虽然也使用.jpe,.jfif和.jif
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.
所以主要问题:为什么JPEG有这么多(有效)扩展名与它相关联?
So the main question: Why does JPEG have so many (valid) extensions associated with it?
在相关的说明中我'我想知道为什么Python确实返回'jpe'而不是'jpg'或'jpeg',因为我看到这些使用最多。
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.
推荐答案
出现 mimetypes.guess_extension
返回所有可能的扩展中的第一个:
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]
所以你会得到以 mimetypes.guess_all_extensions
返回的列表中的第一个,结果是:
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']
我猜为什么 .jpe
也有效:
在DOS和早期Windows版本中,文件名只能包含8个字符和3个字符(参见文章维基百科上的8.3文件名以获取更多信息)。可能是他们将JPEG缩写为.JPE或.jpe - 这就是为什么我们现在有.jpe,.jpeg和.jpg。
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.
确实如此.jpeg和.jpg更常见。
It's indeed true that .jpeg and .jpg are more common.
这篇关于为什么各种JPEG扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!