|
16 | 16 | 'heic',
|
17 | 17 | ]
|
18 | 18 |
|
| 19 | +image_files = [] |
| 20 | +for file_path in sys.argv[1:]: |
| 21 | + file_extension = Path(file_path).suffix[1:].lower() |
| 22 | + if file_extension in WHITELIST_EXT: |
| 23 | + img_suffix = os.getenv('img_suffix') |
| 24 | + target_folder = os.getenv('target_folder') |
| 25 | + path = Path(file_path) |
| 26 | + |
| 27 | + if not (os.getenv('target_folder')) and not (img_suffix): |
| 28 | + img_suffix = '_shrinked' |
| 29 | + |
| 30 | + if target_folder: |
| 31 | + path = Path(target_folder) / path.name |
| 32 | + |
| 33 | + if img_suffix: |
| 34 | + new_file_name = f"{path.stem}{img_suffix}{path.suffix}" |
| 35 | + new_file_path = path.with_name(new_file_name) |
| 36 | + shutil.copyfile(file_path, new_file_path) |
| 37 | + file_path = str(new_file_path) |
| 38 | + |
| 39 | + image_files.append(file_path) |
| 40 | +""" |
19 | 41 | image_files = []
|
20 | 42 | for f in sys.argv[1::]:
|
21 | 43 | ext = Path(f).suffix.replace('.', '').lower()
|
22 | 44 | if ext in WHITELIST_EXT:
|
| 45 | + img_suffix = os.getenv('img_suffix') |
| 46 | + path, filename = os.path.split(f) |
| 47 | + if not (os.getenv('target_folder')) and not (img_suffix): |
| 48 | + img_suffix = '_shrinked' |
| 49 | + if os.getenv('target_folder'): |
| 50 | + path = os.getenv('target_folder') |
23 | 51 | # create a copy if img_suffix is not empty in WF config
|
24 |
| - if os.getenv('img_suffix'): |
25 |
| - path, filename = os.path.split(f) |
| 52 | + if img_suffix: |
26 | 53 | basename, extension = os.path.splitext(filename)
|
27 |
| - new_file_name = f"{basename}{os.getenv('img_suffix')}{extension}" |
| 54 | + new_file_name = f"{basename}{img_suffix}{extension}" |
28 | 55 | new_file = os.path.join(path, new_file_name)
|
29 | 56 | shutil.copyfile(f, new_file)
|
30 | 57 | f = new_file
|
31 | 58 |
|
32 | 59 | image_files.append(f)
|
| 60 | +""" |
33 | 61 |
|
34 | 62 | files = "\t".join(image_files)
|
35 | 63 |
|
|
0 commit comments