Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not unintentionally load TIFF format at first #6892

Merged
merged 1 commit into from Jan 18, 2023

Conversation

radarhere
Copy link
Member

from PIL import Image
Image.preinit()
print(Image.ID)

prints

['BMP', 'DIB', 'GIF', 'TIFF', 'JPEG', 'PPM', 'PNG']

But preinit() doesn't list TIFF. In fact, it is commented out

Pillow/src/PIL/Image.py

Lines 321 to 364 in 43bb035

def preinit():
"""Explicitly load standard file format drivers."""
global _initialized
if _initialized >= 1:
return
try:
from . import BmpImagePlugin
assert BmpImagePlugin
except ImportError:
pass
try:
from . import GifImagePlugin
assert GifImagePlugin
except ImportError:
pass
try:
from . import JpegImagePlugin
assert JpegImagePlugin
except ImportError:
pass
try:
from . import PpmImagePlugin
assert PpmImagePlugin
except ImportError:
pass
try:
from . import PngImagePlugin
assert PngImagePlugin
except ImportError:
pass
# try:
# import TiffImagePlugin
# assert TiffImagePlugin
# except ImportError:
# pass
_initialized = 1

So why is TIFF part of the preinit list? Because when JPEG is loaded, it imports TiffImagePlugin.

from . import Image, ImageFile, TiffImagePlugin

This PR changes the import to only run when it is used, removing TIFF from the list.

@hugovk hugovk merged commit 407f0f9 into python-pillow:main Jan 18, 2023
@radarhere radarhere deleted the init branch January 18, 2023 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants