This repository was archived by the owner on Jun 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathtask_1.py
53 lines (41 loc) · 1.39 KB
/
task_1.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
43
44
45
46
47
48
49
50
51
52
53
import os
from PIL import Image
# Function to process the images
def process_images(input_folder, output_folder, files):
images_details = []
for file in files:
file_path = os.path.join(input_folder, file)
with Image.open(file_path) as img:
# Details
details = {
'filename': file,
'format': img.format,
'mode': img.mode,
'size': img.size
}
images_details.append(details)
# Convert image format to PNG
new_file_name = os.path.splitext(file)[0] + '.png'
new_file_path = os.path.join(output_folder, new_file_name)
img.save(new_file_path, 'PNG')
return images_details
def main():
# Path to the input folder
input_folder = 'input'
output_folder = 'output'
# Create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# List all files in the input folder
files = os.listdir(input_folder)
# Process the images and get their details
try:
image_details = process_images(input_folder, output_folder, files)
# Print the file details.
for detail in image_details:
print(detail)
# Successful Conversion of Images
print("Images Converted Successfully!")
except Exception as e:
print(e)
if __name__ == '__main__':
main()