From 33836992696f2987a0346e5b950f9046db0f7e16 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Mon, 4 Apr 2022 00:41:39 +0200 Subject: [PATCH] Image outputting v0.1 I have not tried it :-) --- lib.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib.py b/lib.py index a95e476..7d90a5d 100644 --- a/lib.py +++ b/lib.py @@ -51,8 +51,29 @@ class Picture: assert result.h == ht return result + def _to_pil(self): + # Create int iterable + # TODO: If this is slow, we should use a generator. + seq = [] + for line in self.pixels: + for pix in line: + seq.extend(pix) + + # bytes… + b = bytes(seq) + + # PIL image + from PIL import Image + img = Image.frombytes('RGB', (self.w, self.h), b) + return img - def show(self): ... + def show(self): + img = self._to_pil() + img.show() + + def save(self, filename): + img = self._to_pil() + img.save(filename) class Interpolator: def interpolate(self, picture, new_h, new_w):