24 lines
530 B
Python
24 lines
530 B
Python
from PIL import Image
|
|
from pathlib import Path
|
|
|
|
source = ''
|
|
target = ''
|
|
|
|
for image in Path(source).glob('*.jpg'):
|
|
|
|
img = Image.open(image)
|
|
width, height = img.size
|
|
|
|
if height > width:
|
|
var = height / width
|
|
new_width = int(1600 / var)
|
|
new_height = 1600
|
|
else:
|
|
var = width / height
|
|
new_width = 1600
|
|
new_height = int(1600 / var)
|
|
|
|
img_final = img.resize((new_width, new_height))
|
|
img_final.save(target + '\\' + image.name, quality=85)
|
|
print(f'file{image} ok!')
|