From c4320863b19d345a8a739f19bd51e987660ab41b Mon Sep 17 00:00:00 2001 From: joak Date: Thu, 11 Apr 2024 14:43:07 +0200 Subject: [PATCH] init --- script.py | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 script.py diff --git a/script.py b/script.py new file mode 100644 index 0000000..d1d91f6 --- /dev/null +++ b/script.py @@ -0,0 +1,88 @@ +from PIL import Image +import glob +import random +from escpos.printer import Usb + +p = Usb(0x4b8, 0x0e15) + +new_image = Image.new('RGBA',(288*2, 288*19), (255,255,255)) + + +for uu in range(0,10): + images = glob.glob("./*.png",recursive=False) + random.shuffle(images) + print(images) + while images: + length = len(images)-1 + r = random.randint(0,length) + img = Image.open(images.pop(r)) + width, height = img.size + if width == height: + img = img.rotate(random.choice((0,90,180,270))) + + if width == 288 and height == 288: + tempImage = Image.new('RGBA',(576, 288),(255,255,255)) + tempImage.paste(img, (0,0)) + counter = 0 + while True: + counter = counter + 1 + length = len(images)-1 + print(length) + if length == -1: + break + r = random.randint(0,length) + img = Image.open(images[r]) + img.rotate(random.choice((0,90,180,270))) + width, height = img.size + if width == 288: + images.pop(r) + break + if counter == 50: + break + tempImage.paste(img, (288,0)) + p.image(tempImage) + elif width == 288 and height == 576: + tempImage = Image.new('RGBA',(576, 576),(255,255,255)) + tempImage.paste(img, (0,0)) + counter = 0 + while True: + counter = counter + 1 + length = len(images)-1 + if length == -1: + break + r = random.randint(0,length) + img = Image.open(images[r]) + img = img.rotate(random.choice((0,90,180,270))) + width, height = img.size + if width == 288 and height == 288: + images.pop(r) + break + if counter == 50: + break + tempImage.paste(img, (288,0)) + counter = 0 + while True: + counter = counter + 1 + length = len(images)-1 + if length == -1: + break + r = random.randint(0,length) + img = Image.open(images[r]) + img = img.rotate(random.choice((0,90,180,270))) + width, height = img.size + if width == 288 and height == 288: + images.pop(r) + break + if counter == 50: + break + tempImage.paste(img, (288,288)) + p.image(tempImage) + else: + p.image(img) + + p.textln() + p.cut() + p.textln() + p.textln() + p.textln() + p.cut()