-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicmerge.py
More file actions
28 lines (22 loc) · 1010 Bytes
/
Copy pathpicmerge.py
File metadata and controls
28 lines (22 loc) · 1010 Bytes
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
import os
from PIL import Image
# Set the input and output folders
input_folder = 'IMSLP_sampledimages256'
output_folder = 'IMSLP_sampledimages128 - Copy'
# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Loop through all the images in the input folder
for filename in os.listdir(input_folder):
# Check if the file is an image
if filename.endswith(('.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tif')):
# Open the image using Pillow
img = Image.open(os.path.join(input_folder, filename))
# Resize the image to half its size
# width, height = img.size
# img = img.resize((width // 2, height // 2))
# Add a subscript to the filename
base, ext = os.path.splitext(filename)
new_filename = f"{base}_half{ext}"
# Save the resized image to the output folder
img.save(os.path.join(output_folder, new_filename))