dir handling

main
alex 2023-10-07 23:19:16 +02:00
parent 3f527bac8c
commit 6d9bb7be3f
9 changed files with 358 additions and 6 deletions

BIN
inputs2/test1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

BIN
inputs2/test2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

BIN
inputs2/test3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 KiB

BIN
inputs2/test4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

16
main.py
View File

@ -13,6 +13,13 @@ output_path = base_path + '/outputs/'
with open('./template.lbrn', 'r') as file:
template = file.read()
# create input folder if not exists
if not os.path.exists(input_path):
os.makedirs(input_path)
print("Created inputs folder. Insert images in this folder and run the script again.")
exit()
# read input files
input_files = os.listdir(input_path)
@ -23,6 +30,9 @@ if len(input_files) == 0:
# delete files in output folder
if not os.path.exists(output_path):
os.makedirs(output_path)
output_files = os.listdir(output_path)
for output_file_name in output_files:
@ -43,15 +53,9 @@ for input_file_name in input_files:
t = template.replace('%image%', base64.b64encode(file_content).decode('utf-8'))
t = t.replace('%imagePath%', file_path)
# write output file
output_path = base_path + '/outputs/'
# remove file extension and add .lbrn
output_file_name = os.path.splitext(input_file_name)[0] + '.lbrn'
if not os.path.exists(output_path):
os.makedirs(output_path)
output_file_path = os.path.join(output_path, output_file_name)
with open(output_file_path, 'w') as file:

87
outputs2/test1.lbrn Normal file

File diff suppressed because one or more lines are too long

87
outputs2/test2.lbrn Normal file

File diff suppressed because one or more lines are too long

87
outputs2/test3.lbrn Normal file

File diff suppressed because one or more lines are too long

87
outputs2/test4.lbrn Normal file

File diff suppressed because one or more lines are too long