mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 02:46:18 +03:00
Extracted core of getdata into _write_frame_data
This commit is contained in:
parent
af57ff8d45
commit
a43295c3dd
|
@ -391,8 +391,7 @@ def _save(im, fp, filename, save_all=False):
|
||||||
|
|
||||||
im_frame = im_frame.crop(frame_data['bbox'])
|
im_frame = im_frame.crop(frame_data['bbox'])
|
||||||
offset = frame_data['bbox'][:2]
|
offset = frame_data['bbox'][:2]
|
||||||
for s in getdata(im_frame, offset, **frame_data['encoderinfo']):
|
_write_frame_data(fp, im_frame, offset, frame_data['encoderinfo'])
|
||||||
fp.write(s)
|
|
||||||
if not save_all:
|
if not save_all:
|
||||||
for s in getheader(im_out, palette, im.encoderinfo)[0]:
|
for s in getheader(im_out, palette, im.encoderinfo)[0]:
|
||||||
fp.write(s)
|
fp.write(s)
|
||||||
|
@ -714,6 +713,19 @@ def getheader(im, palette=None, info=None):
|
||||||
header.append(_get_header_palette(palette_bytes))
|
header.append(_get_header_palette(palette_bytes))
|
||||||
return header, used_palette_colors
|
return header, used_palette_colors
|
||||||
|
|
||||||
|
def _write_frame_data(fp, im_frame, offset, params):
|
||||||
|
try:
|
||||||
|
im_frame.encoderinfo = params
|
||||||
|
|
||||||
|
# local image header
|
||||||
|
_get_local_header(fp, im_frame, offset, 0)
|
||||||
|
|
||||||
|
ImageFile._save(im_frame, fp, [("gif", (0, 0)+im_frame.size, 0,
|
||||||
|
RAWMODE[im_frame.mode])])
|
||||||
|
|
||||||
|
fp.write(b"\0") # end of image data
|
||||||
|
finally:
|
||||||
|
del im_frame.encoderinfo
|
||||||
|
|
||||||
def getdata(im, offset=(0, 0), **params):
|
def getdata(im, offset=(0, 0), **params):
|
||||||
"""Return a list of strings representing this image.
|
"""Return a list of strings representing this image.
|
||||||
|
@ -730,18 +742,7 @@ def getdata(im, offset=(0, 0), **params):
|
||||||
|
|
||||||
fp = Collector()
|
fp = Collector()
|
||||||
|
|
||||||
try:
|
_write_frame_data(fp, im, offset, params)
|
||||||
im.encoderinfo = params
|
|
||||||
|
|
||||||
# local image header
|
|
||||||
_get_local_header(fp, im, offset, 0)
|
|
||||||
|
|
||||||
ImageFile._save(im, fp, [("gif", (0, 0)+im.size, 0, RAWMODE[im.mode])])
|
|
||||||
|
|
||||||
fp.write(b"\0") # end of image data
|
|
||||||
|
|
||||||
finally:
|
|
||||||
del im.encoderinfo
|
|
||||||
|
|
||||||
return fp.data
|
return fp.data
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user