Skip to content

Commit f3bae91

Browse files
committed
Python script creates a Typescript snipped that can be pasted into photos.tx
1 parent 8ec54eb commit f3bae91

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

scripts/filenames-list.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{ src: "Catedral_of_Esztergom.22.3024x4032.jpg", alt: "A photo" },
2+
{ src: "meeks.3684.3024x4032.jpg", alt: "A photo" },
3+
{ src: "Catedral_of_Esztergom.22.3024x4032.jpg", alt: "A photo" },
4+
{ src: "meeks.3684.3024x4032.jpg", alt: "A photo" },
5+
{ src: "Catedral_of_Esztergom.22.3024x4032.jpg", alt: "A photo" },
6+
{ src: "meeks.3684.3024x4032.jpg", alt: "A photo" },

scripts/step01_add_dimensions_to_original_image_names.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ def rename_images_add_dimensions(start_dir, renamed_dir, test=False):
3434
new_name = f"{name}.{width}x{height}{ext}"
3535
if test:
3636
print("new_name: ", new_name)
37+
print(f'{{ src: "{new_name}", alt: "A photo" }},')
3738
new_path = os.path.join(renamed_dir, new_name)
3839
shutil.copy2(img_path, new_path)
3940

41+
# append a Typescript snippet to a file for pasting into 'src/photos.tx'
42+
code = f'{{ src: "{new_name}", alt: "A photo" }},'
43+
with open('filenames-list.txt', 'a') as file:
44+
file.write(code + '\n')
45+
4046

4147
if __name__ == "__main__":
42-
test_dir1 = 'photos/test1' # original photo named XXXX.YYY.jpg
43-
test_dir2 = 'photos/test2' # original photo with dimensions added to name
48+
test_dir1 = 'photos/test/test1' # original photo named XXXX.YYY.jpg
49+
test_dir2 = 'photos/test/test2' # original photo with dimensions added to name
4450
# i.e., XXXX.YYY.WIDTHxHEIGHT.jpg
4551
rename_images_add_dimensions(test_dir1, test_dir2, test=True)

0 commit comments

Comments
 (0)