from PIL import Image
import requests
from io import BytesIO
# URL gambar
url_top = "https://yukngoding.biz.id/28sept/uploads/6803c6886adae-500px.jpg"
url_bottom = "https://yukngoding.biz.id/28sept/uploads/6803c6885ce9f-500px.jpg"
# Ambil gambar dari URL
response_top = requests.get(url_top)
response_bottom = requests.get(url_bottom)
img_top = Image.open(BytesIO(response_top.content))
img_bottom = Image.open(BytesIO(response_bottom.content))
# Samakan lebar gambar
width = max(img_top.width, img_bottom.width)
img_top = img_top.resize((width, int(img_top.height * width / img_top.width)))
img_bottom = img_bottom.resize((width, int(img_bottom.height * width / img_bottom.width)))
# Buat gambar baru untuk gabungan
combined_height = img_top.height + img_bottom.height
combined_image = Image.new("RGB", (width, combined_height))
# Tempelkan gambar atas dan bawah
combined_image.paste(img_top, (0, 0))
combined_image.paste(img_bottom, (0, img_top.height))
# Simpan hasil
combined_image.save("gabungan_gambar.jpg")
combined_image.show()