From 97c60d8ba487cb8cc02bbf59690684e05dc8e77d Mon Sep 17 00:00:00 2001 From: Steve Dogiakos Date: Sat, 19 Feb 2022 13:10:53 -0700 Subject: [PATCH] Update numeral-generator.py --- numeral-generator.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/numeral-generator.py b/numeral-generator.py index efbe12b..bedefdc 100644 --- a/numeral-generator.py +++ b/numeral-generator.py @@ -1,4 +1,8 @@ +import sys from PIL import Image +# alternate way of importing image? +# images = [Image.open(x) for x in ['Test1.jpg', 'Test2.jpg', 'Test3.jpg']] +# widths, heights = zip(*(i.size for i in images)) # get the numeral images - add pack numeals later one = Image.open("one.jpg") two = Image.open("two.jpg") @@ -11,5 +15,30 @@ eight = Image.open("eight.jpg") nine = Image.open("nine.jpg") zero = Image.open("zero.jpg") # get the unit number - add pack as an option later +# make the variable the same as numbers unitno = input("What is your Troop number?") +print(f'You entered {unitno}') # parse the troop number + +# make parsed numbers equal to their numeral +# combining images +# https://stackoverflow.com/questions/30227466/combine-several-images-horizontally-with-python +# alternate method for combining? +# import numpy as np +# import PIL +# from PIL import Image +# +list_im = ['one.jpg', 'two.jpg', 'three.jpg', 'four.jpg', 'five.jpg', 'six.jpg', 'seven.jpg', 'eight.jpg', 'nine.jpg', 'zero.jpg'] +imgs = [ pillow.Image.open(i) for i in list_im ] +# pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here) +min_shape = sorted( [(np.sum(i.size), i.size ) for i in imgs])[0][1] +imgs_comb = np.hstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) ) + +# save that beautiful picture +imgs_comb = PIL.Image.fromarray( imgs_comb) +imgs_comb.save( 'Trifecta.jpg' ) + +# for a vertical stacking it is simple: use vstack +imgs_comb = np.vstack( (np.asarray( i.resize(min_shape) ) for i in imgs ) ) +imgs_comb = PIL.Image.fromarray( imgs_comb) +imgs_comb.save( 'Trifecta_vertical.jpg' )