Add multiple file code and images to use

Signed-off-by: Andy K <donfackandy@gmail.com>
This commit is contained in:
Andy K 2022-11-05 20:51:37 +01:00
parent f8e933cbdc
commit 1e3dd6bc32
8 changed files with 26 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 989 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

@ -0,0 +1 @@
Subproject commit f8e933cbdc76fa3f329c2fdcb3dd5e9cacc23e23

BIN
imageEngine/image_test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 392 KiB

25
imageEngine/umage.py Normal file
View File

@ -0,0 +1,25 @@
from PIL import Image
import itertools
def load(filename):
""" Given a filename that matches an image file,
return a list of lists of tuples corresponding to the list of
lines of pixels (R, G, B) of the image. """
with Image.open(filename, 'r') as image:
image = image.convert('RGB')
content = list(image.getdata())
size_x, size_y = image.size
return [content[i:i + size_x] for i in range(0, len(content), size_x)]
def save(image, filename='new', extension='jpg'):
""" Stores the given image into a file. The name
of the file is set to <filename>.<extension> which is
'new.jpg' by default. """
size_x, size_y = len(image), len(image[0])
new_image = Image.new('RGB', (size_y, size_x))
new_image.putdata(list(itertools.chain.from_iterable(image)))
new_image.save('%s.%s' % (filename, extension))