Skip to content

Commit 077e701

Browse files
committed
refactor(ff7-screenshots): improve dual-display crop logic
1 parent df577c3 commit 077e701

1 file changed

Lines changed: 24 additions & 14 deletions

File tree

‎for_games/Final Fantasy VII etc screenshots/crop_with_two_displays.py‎

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,47 @@
99
from PIL import Image
1010

1111
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"
1313

1414

1515
for path in PATH_DIR.rglob("*.*"):
1616
if path.suffix.lower() not in [".png", ".jpg", ".jpeg"]:
1717
continue
1818

19-
path_img_cropped: Path = PATH_DIR_CROPPED / path.name
19+
path_img_cropped: Path = path.parent / NAME_DIR_CROPPED / path.name
2020
if path_img_cropped.exists():
2121
continue
2222

2323
img = Image.open(path)
2424
width, height = img.size
25-
if width <= 2560:
26-
continue
2725

28-
if width == 4480:
26+
x1: int
27+
y1: int
28+
x2: int
29+
y2: int
30+
31+
if width == 4480: # Картинка на 2 экрана
2932
x1 = 1920
3033
y1 = 0
3134
x2 = width
3235
y2 = height
3336

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
3645

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
4148

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+
)
4453

45-
continue
54+
path_img_cropped.parent.mkdir(parents=True, exist_ok=True)
55+
img_cropped.save(path_img_cropped)

0 commit comments

Comments
 (0)