aboutsummaryrefslogtreecommitdiff
path: root/gantools/image_utils.py
diff options
context:
space:
mode:
authorVee9ahd1 <[email protected]>2019-06-08 17:51:12 -0400
committerVee9ahd1 <[email protected]>2019-06-08 17:51:12 -0400
commit620535b58307e43a80e7f123e590e4fc31b1a755 (patch)
tree047188a39c394b4c3d7dfec67b637730b8714f84 /gantools/image_utils.py
parent16e8cb2ff9cc94265d3ad960d51ac8fa318b1b74 (diff)
added image save callback to sample/render loop
Diffstat (limited to 'gantools/image_utils.py')
-rw-r--r--gantools/image_utils.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/gantools/image_utils.py b/gantools/image_utils.py
index 72130b0..a875a91 100644
--- a/gantools/image_utils.py
+++ b/gantools/image_utils.py
@@ -9,3 +9,22 @@ def save_images(ims, output_dir='', prefix='', format='JPEG'):
for i, im in enumerate(ims):
full_path = os.path.join(output_dir, prefix + str(i).zfill(4) + '.' + format.lower())
save_image(im, full_path, format)
+
+class ImageSaver(object):
+ def __init__(self, output_dir='', prefix='', image_format='JPEG'):
+ self.output_dir = str(output_dir)
+ self.prefix = str(prefix)
+ self.image_format = str(image_format)
+ self.index = int(0)
+ self.quality = 90
+
+ def save(self, ims):
+ for i, im in enumerate(ims):
+ full_path = os.path.join(
+ self.output_dir,
+ self.prefix + str(self.index).zfill(4) + '.' + self.image_format.lower()
+ )
+ image = PIL.Image.fromarray(im)
+ image.save(full_path, format=self.image_format, quality=self.quality)
+ self.index += 1
+