Upload 41 files
Browse files
1.jpg
CHANGED
10.jpg
CHANGED
11.jpg
CHANGED
12.jpg
CHANGED
13.jpg
CHANGED
14.jpg
CHANGED
15.jpg
CHANGED
16.jpg
CHANGED
17.jpg
CHANGED
18.jpg
CHANGED
19.jpg
CHANGED
2.jpg
CHANGED
20.jpg
CHANGED
3.jpg
CHANGED
4.jpg
CHANGED
5.jpg
CHANGED
6.jpg
CHANGED
7.jpg
CHANGED
8.jpg
CHANGED
9.jpg
CHANGED
tset.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import cv2
|
3 |
+
|
4 |
+
# Function to resize image
|
5 |
+
def image_resize(image, width=None, height=None, inter=cv2.INTER_AREA):
|
6 |
+
dim = None
|
7 |
+
(h, w) = image.shape[:2]
|
8 |
+
|
9 |
+
if width is None and height is None:
|
10 |
+
return image
|
11 |
+
|
12 |
+
if width is None:
|
13 |
+
r = height / float(h)
|
14 |
+
dim = (int(w * r), height)
|
15 |
+
else:
|
16 |
+
r = width / float(w)
|
17 |
+
dim = (width, int(h * r))
|
18 |
+
|
19 |
+
resized = cv2.resize(image, dim, interpolation=inter)
|
20 |
+
return resized
|
21 |
+
|
22 |
+
# Function to convert and resize images
|
23 |
+
def convert_and_resize_images_in_folder(folder_path):
|
24 |
+
for filename in os.listdir(folder_path):
|
25 |
+
if filename.lower().endswith(('.png', '.jpeg', '.bmp', '.tiff', '.gif', '.jpg')):
|
26 |
+
file_path = os.path.join(folder_path, filename)
|
27 |
+
|
28 |
+
# Read the image
|
29 |
+
image = cv2.imread(file_path)
|
30 |
+
if image is None:
|
31 |
+
print(f"Error reading {file_path}")
|
32 |
+
continue
|
33 |
+
|
34 |
+
# Resize the image
|
35 |
+
resized_image = image_resize(image, height=1080)
|
36 |
+
|
37 |
+
# Construct the output file name
|
38 |
+
base, ext = os.path.splitext(filename)
|
39 |
+
output_file_path = os.path.join(folder_path, base + '.jpg')
|
40 |
+
|
41 |
+
# Save the image in JPEG format
|
42 |
+
cv2.imwrite(output_file_path, resized_image)
|
43 |
+
print(f"Converted and resized {file_path} to {output_file_path}")
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
folder_path = '.' # current folder
|
47 |
+
convert_and_resize_images_in_folder(folder_path)
|