""" Package comic as self-contained HTML file with all editing features """ import os import base64 import json from pathlib import Path def create_portable_comic(pages_json_path="output/pages.json", output_path="output/comic_portable.html"): """ Create a single HTML file that contains everything: - All images embedded as base64 - All editing functionality - No external dependencies """ # Read pages data with open(pages_json_path, 'r') as f: pages_data = json.load(f) # Convert all images to base64 embedded_images = {} frames_dir = "frames/final" for page in pages_data: for panel in page.get('panels', []): img_name = panel.get('image', '') if img_name and img_name not in embedded_images: img_path = os.path.join(frames_dir, img_name) if os.path.exists(img_path): with open(img_path, 'rb') as img_file: img_data = base64.b64encode(img_file.read()).decode('utf-8') embedded_images[img_name] = f"data:image/png;base64,{img_data}" # Create self-contained HTML html_content = f''' Portable Comic Editor

🎨 Portable Comic Editor

💡 This is a self-contained file! Save this HTML to keep your comic and edits.
You can open and edit it anytime in any browser.

✏️ Interactive Editor

Drag bubbles to move

Double-click to edit text

Save this HTML file to keep edits!

''' # Write the file with open(output_path, 'w', encoding='utf-8') as f: f.write(html_content) return output_path