mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-28 01:48:56 +09:00
- crop youtube thumbnail to 1:1 apec ratio
This commit is contained in:
1 parent
7f02bd9a83
commit
db717ecbea
2 files changed
+22
-4
No files matched your search
@@ -7,7 +7,7 @@ import yt_dlp
|
||||
from PIL import Image
|
||||
|
||||
from src.modules.console_colors import ULTRASINGER_HEAD
|
||||
|
||||
from src.modules.Image.image_helper import crop_image_to_square
|
||||
|
||||
def get_youtube_title(url: str) -> tuple[str, str]:
|
||||
"""Get the title of the YouTube video"""
|
||||
@@ -62,9 +62,9 @@ def download_and_convert_thumbnail(ydl_opts, url: str, clear_filename: str, outp
|
||||
response = ydl.urlopen(thumbnail_url)
|
||||
image_data = response.read()
|
||||
image = Image.open(io.BytesIO(image_data))
|
||||
image.save(
|
||||
os.path.join(output_path, clear_filename + " [CO].jpg"), "JPEG"
|
||||
)
|
||||
image_path = os.path.join(output_path, clear_filename + " [CO].jpg")
|
||||
image.save(image_path, "JPEG")
|
||||
crop_image_to_square(image_path)
|
||||
|
||||
|
||||
def download_youtube_video(url: str, clear_filename: str, output_path: str) -> None:
|
||||
|
||||
@@ -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)
|
||||
Reference in new issue
Block a user