-
Notifications
You must be signed in to change notification settings - Fork 0
/
bulkcrop.py
37 lines (28 loc) · 1019 Bytes
/
bulkcrop.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
36
37
import os
from Katna.image import Image
from Katna.writer import ImageCropDiskWriter
img_module = Image()
image_folder = input("Enter the path to the images folder: ")
output_folder = input("Enter the path to the output images folder: ")
image_files = []
#get image files in the folder
for filename in os.listdir(image_folder):
if not filename.startswith('.') and filename.lower().endswith(('.jpg', '.jpeg', '.png')):
image_files.append(filename)
# Ensure the output folder exists
os.makedirs(output_folder, exist_ok=True)
# diskwriter to save crop data
diskwriter = ImageCropDiskWriter(location=output_folder)
for img in image_files:
input_path = image_folder + '/' + img
output_path = output_folder + '/' + img
crop_list = img_module.crop_image_with_aspect(
file_path=input_path,
crop_aspect_ratio='1:1',
num_of_crops=1,
writer=diskwriter,
filters="text",
down_sample_factor=8
)
print(f"Processed: {img} => {output_path}")
print("Processing complete.")