-
Notifications
You must be signed in to change notification settings - Fork 0
/
SplitLongImage.py
35 lines (26 loc) · 1000 Bytes
/
SplitLongImage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from PIL import Image
# Open the long image
input_image_path = 'path/image.png' # Replace with your image path
long_image = Image.open(input_image_path)
# Dimensions of the long image
long_image_width, long_image_height = long_image.size
# Desired dimensions of each screenshot
screenshot_width = 1024
screenshot_height = 1024
# Calculate the number of screenshots
num_screenshots = long_image_height // screenshot_height
if long_image_height % screenshot_height != 0:
num_screenshots += 1
# Create the screenshots
for i in range(num_screenshots):
left = 0
upper = i * screenshot_height
right = screenshot_width
lower = (i + 1) * screenshot_height
if lower > long_image_height:
lower = long_image_height
# Crop the image to the current screenshot dimensions
screenshot = long_image.crop((left, upper, right, lower))
# Save the screenshot
screenshot.save(f'screenshot_{i + 1}.png')
print(f'{num_screenshots} screenshots created.')