fix: Replace layout text objects instead of updating
Browse filesDelete old title/subtitle objects and create new ones with custom text.
This fixes issues with:
- Split title objects (e.g., "The" + "Tutorial" as separate objects)
- Text truncation
- Overlapping text
Increased render wait time to 2 seconds for better stability.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- mcp_server_comprehensive.py +49 -23
mcp_server_comprehensive.py
CHANGED
|
@@ -424,19 +424,30 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 424 |
objects = objects_result.get("objects", [])
|
| 425 |
text_objects = [obj for obj in objects if obj.get("type") == "text"]
|
| 426 |
|
| 427 |
-
#
|
|
|
|
| 428 |
for obj in text_objects:
|
| 429 |
-
obj_id = obj.get("id")
|
| 430 |
-
obj_text = obj.get("text", "")
|
| 431 |
font_size = obj.get("fontSize", 0)
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
|
| 438 |
-
|
| 439 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 440 |
|
| 441 |
# Update subtitle if specified
|
| 442 |
if subtitle:
|
|
@@ -446,19 +457,34 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 446 |
objects = objects_result.get("objects", [])
|
| 447 |
text_objects = [obj for obj in objects if obj.get("type") == "text"]
|
| 448 |
|
| 449 |
-
# Find subtitle (smaller text
|
|
|
|
| 450 |
for obj in text_objects:
|
| 451 |
-
obj_id = obj.get("id")
|
| 452 |
obj_text = obj.get("text", "").lower()
|
| 453 |
font_size = obj.get("fontSize", 0)
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
if
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
# Add Huggy if specified
|
| 464 |
if huggy_id:
|
|
@@ -470,8 +496,8 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 470 |
result = await execute_api_call(page, "addObject", obj)
|
| 471 |
results.append({"step": "add_custom_object", "result": result})
|
| 472 |
|
| 473 |
-
# Wait for rendering to complete
|
| 474 |
-
await asyncio.sleep(
|
| 475 |
|
| 476 |
# Export the final thumbnail
|
| 477 |
export_result = await execute_api_call(page, "exportCanvas", "png")
|
|
|
|
| 424 |
objects = objects_result.get("objects", [])
|
| 425 |
text_objects = [obj for obj in objects if obj.get("type") == "text"]
|
| 426 |
|
| 427 |
+
# Find large text objects (titles) and delete them
|
| 428 |
+
title_objects = []
|
| 429 |
for obj in text_objects:
|
|
|
|
|
|
|
| 430 |
font_size = obj.get("fontSize", 0)
|
| 431 |
+
if font_size > 100 or "title" in obj.get("id", "").lower():
|
| 432 |
+
title_objects.append(obj)
|
| 433 |
+
|
| 434 |
+
# Delete all old title objects
|
| 435 |
+
for obj in title_objects:
|
| 436 |
+
await execute_api_call(page, "deleteObject", obj.get("id"))
|
| 437 |
+
results.append({"step": "delete_old_title", "objectId": obj.get("id")})
|
| 438 |
+
|
| 439 |
+
# Add new title text
|
| 440 |
+
if title_objects:
|
| 441 |
+
first_title = title_objects[0]
|
| 442 |
+
await execute_api_call(page, "addText", title, {
|
| 443 |
+
"x": first_title.get("x", 73),
|
| 444 |
+
"y": first_title.get("y", 65),
|
| 445 |
+
"fontSize": first_title.get("fontSize", 190),
|
| 446 |
+
"fontFamily": first_title.get("fontFamily", "Inter"),
|
| 447 |
+
"fill": first_title.get("fill", "#000000"),
|
| 448 |
+
"fontWeight": "bold"
|
| 449 |
+
})
|
| 450 |
+
results.append({"step": "add_new_title"})
|
| 451 |
|
| 452 |
# Update subtitle if specified
|
| 453 |
if subtitle:
|
|
|
|
| 457 |
objects = objects_result.get("objects", [])
|
| 458 |
text_objects = [obj for obj in objects if obj.get("type") == "text"]
|
| 459 |
|
| 460 |
+
# Find subtitle objects (smaller text with "subtitle" in text/id)
|
| 461 |
+
subtitle_objects = []
|
| 462 |
for obj in text_objects:
|
|
|
|
| 463 |
obj_text = obj.get("text", "").lower()
|
| 464 |
font_size = obj.get("fontSize", 0)
|
| 465 |
+
obj_id = obj.get("id", "").lower()
|
| 466 |
+
|
| 467 |
+
if "subtitle" in obj_text or "subtitle" in obj_id or "description" in obj_id:
|
| 468 |
+
subtitle_objects.append(obj)
|
| 469 |
+
|
| 470 |
+
# Delete old subtitle objects
|
| 471 |
+
for obj in subtitle_objects:
|
| 472 |
+
await execute_api_call(page, "deleteObject", obj.get("id"))
|
| 473 |
+
results.append({"step": "delete_old_subtitle", "objectId": obj.get("id")})
|
| 474 |
+
|
| 475 |
+
# Add new subtitle text
|
| 476 |
+
if subtitle_objects:
|
| 477 |
+
first_subtitle = subtitle_objects[0]
|
| 478 |
+
await execute_api_call(page, "addText", subtitle, {
|
| 479 |
+
"x": first_subtitle.get("x", 84),
|
| 480 |
+
"y": first_subtitle.get("y", 428),
|
| 481 |
+
"fontSize": first_subtitle.get("fontSize", 68),
|
| 482 |
+
"fontFamily": first_subtitle.get("fontFamily", "Inter"),
|
| 483 |
+
"fill": first_subtitle.get("fill", "#FFFFFF"),
|
| 484 |
+
"hasBackground": first_subtitle.get("hasBackground", True),
|
| 485 |
+
"backgroundColor": first_subtitle.get("backgroundColor", "#000000")
|
| 486 |
+
})
|
| 487 |
+
results.append({"step": "add_new_subtitle"})
|
| 488 |
|
| 489 |
# Add Huggy if specified
|
| 490 |
if huggy_id:
|
|
|
|
| 496 |
result = await execute_api_call(page, "addObject", obj)
|
| 497 |
results.append({"step": "add_custom_object", "result": result})
|
| 498 |
|
| 499 |
+
# Wait for rendering to complete (longer wait after adding new objects)
|
| 500 |
+
await asyncio.sleep(2)
|
| 501 |
|
| 502 |
# Export the final thumbnail
|
| 503 |
export_result = await execute_api_call(page, "exportCanvas", "png")
|