|
9 | 9 | from PIL import Image |
10 | 10 |
|
11 | 11 | PATH_DIR: Path = Path(r"C:\Users\ipetrash\Desktop\FF7 Screenshots") |
12 | | -PATH_DIR_CROPPED: Path = PATH_DIR / "cropped" |
| 12 | +NAME_DIR_CROPPED: str = "cropped" |
13 | 13 |
|
14 | 14 |
|
15 | 15 | for path in PATH_DIR.rglob("*.*"): |
16 | 16 | if path.suffix.lower() not in [".png", ".jpg", ".jpeg"]: |
17 | 17 | continue |
18 | 18 |
|
19 | | - path_img_cropped: Path = PATH_DIR_CROPPED / path.name |
| 19 | + path_img_cropped: Path = path.parent / NAME_DIR_CROPPED / path.name |
20 | 20 | if path_img_cropped.exists(): |
21 | 21 | continue |
22 | 22 |
|
23 | 23 | img = Image.open(path) |
24 | 24 | width, height = img.size |
25 | | - if width <= 2560: |
26 | | - continue |
27 | 25 |
|
28 | | - if width == 4480: |
| 26 | + x1: int |
| 27 | + y1: int |
| 28 | + x2: int |
| 29 | + y2: int |
| 30 | + |
| 31 | + if width == 4480: # Картинка на 2 экрана |
29 | 32 | x1 = 1920 |
30 | 33 | y1 = 0 |
31 | 34 | x2 = width |
32 | 35 | y2 = height |
33 | 36 |
|
34 | | - img_cropped = img.crop((x1, y1, x2, y2)) |
35 | | - crop_width, crop_height = img_cropped.size |
| 37 | + elif width == 2560 and height == 1440: |
| 38 | + x1 = 0 |
| 39 | + y1 = 30 |
| 40 | + x2 = width |
| 41 | + y2 = 1390 |
| 42 | + |
| 43 | + else: |
| 44 | + continue |
36 | 45 |
|
37 | | - print( |
38 | | - f"Cropping image {width}x{height} -> {crop_width}x{crop_height} " |
39 | | - f'from "{path}" to "{path_img_cropped}"' |
40 | | - ) |
| 46 | + img_cropped = img.crop((x1, y1, x2, y2)) |
| 47 | + crop_width, crop_height = img_cropped.size |
41 | 48 |
|
42 | | - path_img_cropped.parent.mkdir(parents=True, exist_ok=True) |
43 | | - img_cropped.save(path_img_cropped) |
| 49 | + print( |
| 50 | + f"Cropping image {width}x{height} -> {crop_width}x{crop_height} " |
| 51 | + f'from "{path}" to "{path_img_cropped}"' |
| 52 | + ) |
44 | 53 |
|
45 | | - continue |
| 54 | + path_img_cropped.parent.mkdir(parents=True, exist_ok=True) |
| 55 | + img_cropped.save(path_img_cropped) |
0 commit comments