Skip to content

Commit 8934081

Browse files
authored
Merge pull request #7399 from radarhere/mime
2 parents c556c5f + cabfed9 commit 8934081

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

docs/reference/Image.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,14 @@ Generating images
9393
Registering plugins
9494
^^^^^^^^^^^^^^^^^^^
9595

96+
.. autofunction:: preinit
97+
.. autofunction:: init
98+
9699
.. note::
97100

98-
These functions are for use by plugin authors. Application authors can
99-
ignore them.
101+
These functions are for use by plugin authors. They are called when a
102+
plugin is loaded as part of :py:meth:`~preinit()` or :py:meth:`~init()`.
103+
Application authors can ignore them.
100104

101105
.. autofunction:: register_open
102106
.. autofunction:: register_mime

src/PIL/Image.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,11 @@ def getmodebands(mode):
298298

299299

300300
def preinit():
301-
"""Explicitly load standard file format drivers."""
301+
"""
302+
Explicitly loads BMP, GIF, JPEG, PPM and PPM file format drivers.
303+
304+
It is called when opening or saving images.
305+
"""
302306

303307
global _initialized
304308
if _initialized >= 1:
@@ -334,11 +338,6 @@ def preinit():
334338
assert PngImagePlugin
335339
except ImportError:
336340
pass
337-
# try:
338-
# import TiffImagePlugin
339-
# assert TiffImagePlugin
340-
# except ImportError:
341-
# pass
342341

343342
_initialized = 1
344343

@@ -347,6 +346,9 @@ def init():
347346
"""
348347
Explicitly initializes the Python Imaging Library. This function
349348
loads all available file format drivers.
349+
350+
It is called when opening or saving images if :py:meth:`~preinit()` is
351+
insufficient, and by :py:meth:`~PIL.features.pilinfo`.
350352
"""
351353

352354
global _initialized
@@ -3407,8 +3409,12 @@ def register_open(id, factory, accept=None):
34073409

34083410
def register_mime(id, mimetype):
34093411
"""
3410-
Registers an image MIME type. This function should not be used
3411-
in application code.
3412+
Registers an image MIME type by populating ``Image.MIME``. This function
3413+
should not be used in application code.
3414+
3415+
``Image.MIME`` provides a mapping from image format identifiers to mime
3416+
formats, but :py:meth:`~PIL.ImageFile.ImageFile.get_format_mimetype` can
3417+
provide a different result for specific images.
34123418
34133419
:param id: An image format identifier.
34143420
:param mimetype: The image MIME type for this format.

0 commit comments

Comments
 (0)