resize_image_rework
This commit is contained in:
parent
dd79d8981b
commit
106b510587
@ -1,13 +1,19 @@
|
||||
import glob
|
||||
import PIL.Image
|
||||
|
||||
photos = glob.glob('photos/2/*.jpg')
|
||||
import os
|
||||
x = 2
|
||||
photos = glob.glob(f'photos/{x}/*.jpg')
|
||||
|
||||
for image in photos:
|
||||
print(image)
|
||||
img = PIL.Image.open(image)
|
||||
img.save(image.replace('.jpg', '.webp'))
|
||||
big_image = image.replace('.jpg', '.webp')
|
||||
if os.path.exists(big_image):
|
||||
continue
|
||||
img.save(big_image)
|
||||
ratio = 400/max(img.height, img.width)
|
||||
img = img.resize((int(img.width * ratio), int(img.height * ratio)))
|
||||
image = image.replace('photos/', 'photos/thumbnail/').replace('.jpg', '.webp')
|
||||
img.save(image, quality=50, subsampling=2)
|
||||
small_image = image.replace(f'photos/{x}/', f'photos/{x}/thumbnail/').replace('.jpg', '.webp')
|
||||
if os.path.exists(small_image):
|
||||
continue
|
||||
img.save(small_image, quality=50, subsampling=2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user