fix: Calculate proper text width/height and deselect before export
Browse files- Calculate text dimensions based on fontSize and text length
- Title: 0.6 * fontSize * length for width, 1.5 * fontSize for height
- Subtitle: Same calculation approach
- Deselect all objects before export to remove selection handles
- Added 0.5s wait after deselection
This ensures text displays fully without truncation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
- mcp_server_comprehensive.py +20 -2
mcp_server_comprehensive.py
CHANGED
|
@@ -447,12 +447,19 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 447 |
# Add new title text
|
| 448 |
if title_objects:
|
| 449 |
first_title = title_objects[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
await execute_api_call(page, "addObject", {
|
| 451 |
"type": "text",
|
| 452 |
"text": title,
|
| 453 |
"x": first_title.get("x", 73),
|
| 454 |
"y": first_title.get("y", 65),
|
| 455 |
-
"
|
|
|
|
|
|
|
| 456 |
"fontFamily": first_title.get("fontFamily", "Inter"),
|
| 457 |
"fill": first_title.get("fill", "#000000"),
|
| 458 |
"fontWeight": "bold",
|
|
@@ -493,12 +500,19 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 493 |
# Add new subtitle text
|
| 494 |
if subtitle_objects:
|
| 495 |
first_subtitle = subtitle_objects[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
await execute_api_call(page, "addObject", {
|
| 497 |
"type": "text",
|
| 498 |
"text": subtitle,
|
| 499 |
"x": first_subtitle.get("x", 84),
|
| 500 |
"y": first_subtitle.get("y", 428),
|
| 501 |
-
"
|
|
|
|
|
|
|
| 502 |
"fontFamily": first_subtitle.get("fontFamily", "Inter"),
|
| 503 |
"fill": first_subtitle.get("fill", "#FFFFFF"),
|
| 504 |
"hasBackground": first_subtitle.get("hasBackground", True),
|
|
@@ -521,6 +535,10 @@ async def create_thumbnail(inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
| 521 |
# Wait for rendering to complete (longer wait after adding new objects)
|
| 522 |
await asyncio.sleep(2)
|
| 523 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 524 |
# Export the final thumbnail
|
| 525 |
export_result = await execute_api_call(page, "exportCanvas", "png")
|
| 526 |
results.append({"step": "export", "result": export_result})
|
|
|
|
| 447 |
# Add new title text
|
| 448 |
if title_objects:
|
| 449 |
first_title = title_objects[0]
|
| 450 |
+
# Calculate appropriate width (rough estimate: 0.6 * fontSize * text length)
|
| 451 |
+
font_size = first_title.get("fontSize", 190)
|
| 452 |
+
text_width = max(len(title) * font_size * 0.6, 400)
|
| 453 |
+
text_height = font_size * 1.5
|
| 454 |
+
|
| 455 |
await execute_api_call(page, "addObject", {
|
| 456 |
"type": "text",
|
| 457 |
"text": title,
|
| 458 |
"x": first_title.get("x", 73),
|
| 459 |
"y": first_title.get("y", 65),
|
| 460 |
+
"width": text_width,
|
| 461 |
+
"height": text_height,
|
| 462 |
+
"fontSize": font_size,
|
| 463 |
"fontFamily": first_title.get("fontFamily", "Inter"),
|
| 464 |
"fill": first_title.get("fill", "#000000"),
|
| 465 |
"fontWeight": "bold",
|
|
|
|
| 500 |
# Add new subtitle text
|
| 501 |
if subtitle_objects:
|
| 502 |
first_subtitle = subtitle_objects[0]
|
| 503 |
+
# Calculate appropriate width for subtitle
|
| 504 |
+
font_size = first_subtitle.get("fontSize", 68)
|
| 505 |
+
text_width = max(len(subtitle) * font_size * 0.6, 300)
|
| 506 |
+
text_height = font_size * 1.5
|
| 507 |
+
|
| 508 |
await execute_api_call(page, "addObject", {
|
| 509 |
"type": "text",
|
| 510 |
"text": subtitle,
|
| 511 |
"x": first_subtitle.get("x", 84),
|
| 512 |
"y": first_subtitle.get("y", 428),
|
| 513 |
+
"width": text_width,
|
| 514 |
+
"height": text_height,
|
| 515 |
+
"fontSize": font_size,
|
| 516 |
"fontFamily": first_subtitle.get("fontFamily", "Inter"),
|
| 517 |
"fill": first_subtitle.get("fill", "#FFFFFF"),
|
| 518 |
"hasBackground": first_subtitle.get("hasBackground", True),
|
|
|
|
| 535 |
# Wait for rendering to complete (longer wait after adding new objects)
|
| 536 |
await asyncio.sleep(2)
|
| 537 |
|
| 538 |
+
# Deselect all objects before export (removes selection handles)
|
| 539 |
+
await execute_api_call(page, "deselectAll")
|
| 540 |
+
await asyncio.sleep(0.5)
|
| 541 |
+
|
| 542 |
# Export the final thumbnail
|
| 543 |
export_result = await execute_api_call(page, "exportCanvas", "png")
|
| 544 |
results.append({"step": "export", "result": export_result})
|