You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.0 KiB
Python

8 months ago
from PIL import Image
import glob
import random
from escpos.printer import Usb
p = Usb(0x4b8, 0x0e03)
8 months ago
new_image = Image.new('RGBA',(288*2, 288*19), (255,255,255))
for uu in range(0,1):
images = glob.glob("images/*.png",recursive=False)
8 months ago
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()