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

关于Image.open()的疑惑 #2

Open
highwayMo opened this issue Apr 12, 2022 · 0 comments
Open

关于Image.open()的疑惑 #2

highwayMo opened this issue Apr 12, 2022 · 0 comments

Comments

@highwayMo
Copy link

在阅读Image.open()的源码
源码🔗

def open(fp, mode="r", formats=None):

    if mode != "r":
        raise ValueError(f"bad mode {repr(mode)}")
    elif isinstance(fp, io.StringIO):
        raise ValueError(
            "StringIO cannot be used to open an image. "
            "Binary data must be used instead."
        )

    if formats is None:
        formats = ID
    elif not isinstance(formats, (list, tuple)):
        raise TypeError("formats must be a list or tuple")

    exclusive_fp = False
    filename = ""
    if isinstance(fp, Path):
        filename = str(fp.resolve())
    elif isPath(fp):
        filename = fp

    if filename:
        fp = builtins.open(filename, "rb")
        exclusive_fp = True

    try:
        fp.seek(0)
    except (AttributeError, io.UnsupportedOperation):
        fp = io.BytesIO(fp.read())
        exclusive_fp = True

    prefix = fp.read(16)

    preinit()

    accept_warnings = []

没有找到哪里有用到_open_core()
万忙之中如有闲余时间解答不胜感激

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

No branches or pull requests

1 participant