diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 0000000..15a8f14
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,37 @@
+# Changelog
+
+All notable changes to the Google Font Text Image Node for ComfyUI will be documented in this file.
+
+## [2025-10-22]
+
+### Added
+- **Playwright Integration**: Migrated from html2image to Playwright for more reliable rendering
+- **Automatic Dimension Calculation**: Added ability to set width or height to -1 for automatic sizing based on text content
+- **Text Wrapping**: Implemented proper text wrapping when using fixed canvas dimensions
+- **Individual Padding Controls**: Added separate controls for top, right, bottom, and left padding (0-200px range)
+- **Enhanced Text Positioning**: Improved CSS layout with precise control over text positioning
+
+### Changed
+- Replaced `html2image` dependency with `playwright` for better rendering capabilities
+- Updated HTML/CSS generation to support both auto-sizing and fixed-dimension layouts
+- Modified width/height parameters to accept -1 for automatic sizing
+- Improved font loading with explicit wait time for better reliability
+- Enhanced dimension calculation logic to account for padding values in auto-sizing mode
+
+### Fixed
+- Text cutoff issues that were common with html2image
+- Inability to automatically size images based on content
+- Poor text wrapping behavior with long text strings
+- Limited control over text positioning within the canvas
+
+### Deprecated
+- html2image rendering engine (replaced by Playwright)
+
+## [2024-XX-XX] - Initial Release
+
+### Added
+- Initial release of the Google Font Text Image Node
+- Support for Google Fonts API integration
+- Basic text rendering with typographic controls
+- Dual output modes (Custom Text and Standard Character Set)
+- Transparent background support
\ No newline at end of file
diff --git a/README.md b/README.md
index dbfe481..d2b2d00 100644
--- a/README.md
+++ b/README.md
@@ -7,13 +7,13 @@
This custom node provides a powerful and flexible way to create images from text with advanced typographic controls. It's an ideal tool for generating inputs for Typography, creating titles and watermarks, or producing font specimens for multimodal models to analyze and generate.
-
+
Click below to see the video example:
@@ -26,6 +26,9 @@ Click below to see the video example:
- **Dual Output Modes:**
- **Custom Text:** Render any text you input, respecting line breaks (`\n`).
- **Standard Character Set:** Generate a font specimen image (A-Z, a-z, 0-9, symbols) to capture the font's overall style as reference for multimodal models.
+- **Automatic Dimension Calculation:** Set width or height to -1 to automatically size the image based on text content (requires Playwright).
+- **Text Wrapping:** Text automatically wraps within specified dimensions when using fixed width/height values.
+- **Individual Padding Controls:** Fine-tune text positioning with independent controls for top, right, bottom, and left padding.
- **Transparent Background:** Output a clean RGB image and a corresponding alpha mask, perfect for compositing and layering.
- **Dynamic Font Variant Validation:** The node intelligently checks if a selected font weight/style is available and provides a graceful fallback if it isn't.
@@ -47,9 +50,15 @@ Click below to see the video example:
```bash
pip install -r ComfyUI_Google-Font/requirements.txt
```
- *(This will install `requests`, `html2image`, and `python-dotenv`.)*
-4. **Restart ComfyUI:**
+4. **Install Playwright browser binaries:**
+ Run the following command to install the necessary browser binaries for Playwright:
+ ```bash
+ playwright install
+ ```
+ *(Note: You may need to run this in your activated virtual environment)*
+
+5. **Restart ComfyUI:**
You must completely restart ComfyUI for the node to be loaded.
## Google Fonts API Key (Recommended)
@@ -80,8 +89,9 @@ The node will automatically detect and use this key on the next restart.
| `font_family` | A dropdown list of all available Google Fonts. |
| `output_mode` | - **Custom Text:** Renders the text from the `text` input box. - **Standard Character Set:** Renders a predefined set of characters. |
| `text` | The text you want to display. Supports multiple lines. Ignored if `output_mode` is "Standard Character Set". |
-| `width` / `height` | The dimensions of the output image in pixels. |
-| `font_size` | The size of the font in points. **(See Troubleshooting for text cut-off)** |
+| `dimension_mode` | Choose between "Auto" (automatic sizing based on text content) or "Define Manually" (fixed width/height). |
+| `width` / `height` | The dimensions of the output image in pixels (64-8192). Only used when `dimension_mode` is "Define Manually". |
+| `font_size` | The size of the font in points. |
| `font_weight` | The thickness of the font (e.g., `100` for Thin, `400`/`regular` for Normal, `700` for Bold). |
| `font_style` | Choose between `normal` and `italic`. |
| `text_align` | Horizontal alignment of the text: `center`, `left`, or `right`. |
@@ -90,6 +100,10 @@ The node will automatically detect and use this key on the next restart.
| `text_color` | The color of the text in hex format (e.g., `#000000` for black). Use with an external color picker node. |
| `background_color` | The color of the background in hex format (e.g., `#FFFFFF` for white). Ignored if `transparent_background` is checked. |
| `transparent_background` | **(Recommended)** If checked, the background will be transparent, and the `MASK` output will contain the text's shape. |
+| `padding_top` | Top padding in pixels (0-200). Controls the space between text and the top edge. |
+| `padding_right` | Right padding in pixels (0-200). Controls the space between text and the right edge. |
+| `padding_bottom` | Bottom padding in pixels (0-200). Controls the space between text and the bottom edge. |
+| `padding_left` | Left padding in pixels (0-200). Controls the space between text and the left edge. |
### Node Outputs
@@ -107,18 +121,26 @@ A powerful use case is to layer the generated text over another image.
3. Load a base image using a `Load Image` node.
4. Use a `Composite` or `Layer Style` node to combine the base image with the `IMAGE` and `MASK` from the Google Font Node.
-
-
## Troubleshooting
#### **Help! My text is getting cut off (truncated)!**
-This is the most common issue. This node **does not automatically resize the font** to fit the image. If the text is too large for the canvas, it will be cut off.
+This issue has been significantly improved with the Playwright migration. You now have two solutions:
-To fix this, you must **manually adjust the settings**:
+**Solution 1: Use Auto-Sizing**
+1. Set `dimension_mode` to **Auto** for automatic sizing based on text content.
+
+**Solution 2: Manual Adjustments**
1. **Decrease** the `font_size`.
-2. **Increase** the `width` or `height` of the image.
-3. **Decrease** the `line_height` if you have multiple lines of text.
+2. **Increase** the `width` or `height` of the image when in "Define Manually" mode.
+3. **Increase** the `padding` values to provide more space around the text.
+4. **Decrease** the `line_height` if you have multiple lines of text.
+
+#### **Playwright Browser Not Found Error**
+
+If you get a browser not found error after installation:
+1. Run `playwright install` in your terminal/command prompt to install browser binaries.
+2. Make sure to activate your virtual environment before running the command.
#### **The node doesn't appear in ComfyUI after installation.**
@@ -133,4 +155,8 @@ This can happen if the node fails to connect to the Google Fonts API.
## License
-This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
\ No newline at end of file
+This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
+
+## Changelog
+
+See the [CHANGELOG](CHANGELOG.md) file for a complete history of changes.
\ No newline at end of file
diff --git a/font_utils.py b/font_utils.py
index 40261b8..b6ce54a 100644
--- a/font_utils.py
+++ b/font_utils.py
@@ -26,8 +26,9 @@ def get_google_fonts_data(api_key):
print(f"GoogleFontNode: ERROR! Failed to fetch Google Fonts list: {e}")
return []
-# --- SIMPLE GOOGLE FONT HTML RENDERER ---
-def create_simple_google_font_html(font_family, text, width, height, style_params):
+# --- PLAYWRIGHT-READY HTML RENDERER ---
+def create_playwright_google_font_html(font_family, text, style_params, width=None, height=None):
+ """Creates HTML content optimized for Playwright with automatic sizing and optional text wrapping"""
google_font_url_name = font_family.replace(' ', '+')
escaped_text = text.replace('&', '&').replace('<', '<').replace('>', '>').replace('\n', ' ')
@@ -39,33 +40,100 @@ def create_simple_google_font_html(font_family, text, width, height, style_param
text_transform = style_params.get('text_transform', 'none')
text_color = style_params.get('text_color', '#000000')
background_color = style_params.get('background_color', '#FFFFFF')
+ padding_top = style_params.get('padding_top', 20)
+ padding_right = style_params.get('padding_right', 20)
+ padding_bottom = style_params.get('padding_bottom', 20)
+ padding_left = style_params.get('padding_left', 20)
# Construct the font URL with the specific weights and styles needed
font_request_url = f"https://fonts.googleapis.com/css2?family={google_font_url_name}:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
- html_content = f"""
-
-
-
{escaped_text}
- """
+ # If specific width/height are provided, we want to enable text wrapping
+ if width and width > 0:
+ # Fixed width layout with text wrapping
+ html_content = f"""
+
+
+
+
+
+
+
+
+