MCPcopy Index your code
hub / github.com/python-pillow/Pillow / _save

Function _save

src/PIL/ImageFile.py:644–669  ·  view source on GitHub ↗

Helper to save image based on tile list :param im: Image object. :param fp: File object. :param tile: Tile list. :param bufsize: Optional buffer size

(im: Image.Image, fp: IO[bytes], tile: list[_Tile], bufsize: int = 0)

Source from the content-addressed store, hash-verified

642
643
644def _save(im: Image.Image, fp: IO[bytes], tile: list[_Tile], bufsize: int = 0) -> None:
645 """Helper to save image based on tile list
646
647 :param im: Image object.
648 :param fp: File object.
649 :param tile: Tile list.
650 :param bufsize: Optional buffer size
651 """
652
653 im.load()
654 if not hasattr(im, "encoderconfig"):
655 im.encoderconfig = ()
656 tile.sort(key=_tilesort)
657 # FIXME: make MAXBLOCK a configuration parameter
658 # It would be great if we could have the encoder specify what it needs
659 # But, it would need at least the image size in most cases. RawEncode is
660 # a tricky case.
661 bufsize = max(MAXBLOCK, bufsize, im.size[0] * 4) # see RawEncode.c
662 try:
663 fh = fp.fileno()
664 fp.flush()
665 _encode_tile(im, fp, tile, bufsize, fh)
666 except (AttributeError, io.UnsupportedOperation) as exc:
667 _encode_tile(im, fp, tile, bufsize, None, exc)
668 if hasattr(fp, "flush"):
669 fp.flush()
670
671
672def _encode_tile(

Callers

nothing calls this directly

Calls 4

_encode_tileFunction · 0.85
filenoMethod · 0.80
loadMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…