-
Notifications
You must be signed in to change notification settings - Fork 60
/
example_image_resize_from_dir.py
42 lines (31 loc) · 1.11 KB
/
example_image_resize_from_dir.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
38
39
40
41
42
import os.path
from Katna.image import Image
import os
import ntpath
def main():
img_module = Image()
# folder to save resized images
output_folder_resized_image = "resizedimages"
if not os.path.isdir(os.path.join(".", output_folder_resized_image)):
os.mkdir(os.path.join(".", output_folder_resized_image))
# resized image dimensions
resize_width = 500
resize_height = 600
# Input folder file path
input_folder_path = os.path.join(".", "tests", "data")
print(f"input_folder_path = {input_folder_path}")
resized_images = img_module.resize_image_from_dir(
dir_path=input_folder_path,
target_width=resize_width,
target_height=resize_height,
down_sample_factor=8,
)
for filepath, resized_image in resized_images.items():
# name of the image file
filename = ntpath.basename(filepath)
name = filename.split(".")[0]
# folder path where the images will be stored
img_module.save_image_to_disk(
resized_image, output_folder_resized_image, name + "_resized" + "_", ".jpeg"
)
main()