added some comments

This commit is contained in:
2022-01-26 00:47:00 +01:00
parent b2a3242112
commit a4098b05c2

View File

@@ -27,12 +27,16 @@ except Exception as e:
def compressor(file, quality, resize, size): def compressor(file, quality, resize, size):
# get filepath of image
filepath = os.path.join(os.getcwd(), file) filepath = os.path.join(os.getcwd(), file)
# open image
with Image.open(filepath) as image: with Image.open(filepath) as image:
# resize and compress landscape images
if resize and image.width >= size and image.width > image.height: if resize and image.width >= size and image.width > image.height:
print('resize and compress: ' + file) print('resizing: ' + file)
cover = resizeimage.resize_width(image, size) cover = resizeimage.resize_width(image, size)
print('compressing: ' + file)
cover.save( cover.save(
str(final_path) + '/' + 'min-' + file, str(final_path) + '/' + 'min-' + file,
image.format, image.format,
@@ -40,9 +44,11 @@ def compressor(file, quality, resize, size):
quality=quality, quality=quality,
resample=Image.LANCZOS resample=Image.LANCZOS
) )
# resize and compress portrait images
elif resize and image.height >= size and image.height > image.width: elif resize and image.height >= size and image.height > image.width:
print('resize and compress: ' + file) print('resizing: ' + file)
cover = resizeimage.resize_height(image, size) cover = resizeimage.resize_height(image, size)
print('compressing: ' + file)
cover.save( cover.save(
str(final_path) + '/' + 'min-' + file, str(final_path) + '/' + 'min-' + file,
image.format, image.format,
@@ -50,6 +56,7 @@ def compressor(file, quality, resize, size):
quality=quality, quality=quality,
resample=Image.LANCZOS resample=Image.LANCZOS
) )
# compress images
else: else:
print('compress: ' + file) print('compress: ' + file)
image.save( image.save(