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