Skip to content

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

Description

@highwayMo

在阅读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()
万忙之中如有闲余时间解答不胜感激

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions