mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 19:06:18 +03:00
Image._dump: Rewrite for clarity and type-safety.
This commit is contained in:
parent
ab6c60da1c
commit
72b3e6819d
18
PIL/Image.py
18
PIL/Image.py
|
@ -583,21 +583,27 @@ class Image(object):
|
||||||
|
|
||||||
def _dump(self, file=None, format=None, **options):
|
def _dump(self, file=None, format=None, **options):
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
suffix = ''
|
suffix = ''
|
||||||
if format:
|
if format:
|
||||||
suffix = '.'+format
|
suffix = '.'+format
|
||||||
|
|
||||||
if not file:
|
if not file:
|
||||||
f, file = tempfile.mkstemp(suffix)
|
f, filename = tempfile.mkstemp(suffix)
|
||||||
os.close(f)
|
os.close(f)
|
||||||
|
else:
|
||||||
|
filename = file
|
||||||
|
if not filename.endswith(suffix):
|
||||||
|
filename = filename + suffix
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
if not format or format == "PPM":
|
if not format or format == "PPM":
|
||||||
self.im.save_ppm(file)
|
self.im.save_ppm(filename)
|
||||||
else:
|
else:
|
||||||
if not file.endswith(format):
|
self.save(filename, format, **options)
|
||||||
file = file + "." + format
|
|
||||||
self.save(file, format, **options)
|
return filename
|
||||||
return file
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
return (self.__class__.__name__ == other.__class__.__name__ and
|
return (self.__class__.__name__ == other.__class__.__name__ and
|
||||||
|
|
Loading…
Reference in New Issue
Block a user