Spaces:
Running
Running
Fix: auto-resize character image before upload for Kling Motion
Browse files
src/content_engine/api/routes_video.py
CHANGED
|
@@ -309,6 +309,18 @@ async def _generate_kling_motion_video(
|
|
| 309 |
import aiohttp
|
| 310 |
|
| 311 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
_video_jobs[job_id]["message"] = "Uploading character image..."
|
| 313 |
image_url = await _wavespeed_provider._upload_temp_image(image_bytes)
|
| 314 |
logger.info("Kling motion: character image uploaded: %s", image_url[:80])
|
|
|
|
| 309 |
import aiohttp
|
| 310 |
|
| 311 |
try:
|
| 312 |
+
# Resize image if too large (Kling Motion limit)
|
| 313 |
+
from PIL import Image
|
| 314 |
+
import io
|
| 315 |
+
img = Image.open(io.BytesIO(image_bytes))
|
| 316 |
+
max_size = 1280
|
| 317 |
+
if img.width > max_size or img.height > max_size:
|
| 318 |
+
img.thumbnail((max_size, max_size), Image.LANCZOS)
|
| 319 |
+
buf = io.BytesIO()
|
| 320 |
+
img.save(buf, format="JPEG", quality=90)
|
| 321 |
+
image_bytes = buf.getvalue()
|
| 322 |
+
logger.info("Resized character image to %dx%d", img.width, img.height)
|
| 323 |
+
|
| 324 |
_video_jobs[job_id]["message"] = "Uploading character image..."
|
| 325 |
image_url = await _wavespeed_provider._upload_temp_image(image_bytes)
|
| 326 |
logger.info("Kling motion: character image uploaded: %s", image_url[:80])
|