- crop youtube thumbnail to 1:1 apec ratio

This commit is contained in:
Vadim committed 2023-06-18 22:13:21 +02:00
1 parent 7f02bd9a83
commit db717ecbea
2 files changed
+22 -4

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
from PIL import Image
def crop_image_to_square(image_path):
image = Image.open(image_path)
width, height = image.size
size = min(width, height)
# Calculate the coordinates for the crop
left = (width - size) // 2
top = (height - size) // 2
right = left + size
bottom = top + size
cropped_image = image.crop((left, top, right, bottom))
# Override the original image with the cropped version
cropped_image.save(image_path)