c

 

from flask import Flask, request, send_file from PIL import Image, ImageDraw, ImageFont import os, zipfile, textwrap from datetime import datetime app = Flask(__name__) OUTPUT_DIR = "output" os.makedirs(OUTPUT_DIR, exist_ok=True) # TEXT IN CHUNKS AUFTEILEN def split_text(text, max_length=300): words = text.split() chunks = [] current = [] for word in words: current.append(word) if len(" ".join(current)) >= max_length: chunks.append(" ".join(current)) current = [] if current: chunks.append(" ".join(current)) return chunks # BILD ERZEUGEN def create_image(text, path): width, height = 1080, 1080 img = Image.new("RGB", (width, height), (15, 15, 15)) draw = ImageDraw.Draw(img) # Font (Fallback sicher) try: font = ImageFont.truetype("arial.ttf", 55) except: font = ImageFont.load_default() wrapped = textwrap.fill(text, width=28) bbox = draw.multiline_textbbox((0, 0), wrapped, font=font) x = (width - (bbox[2] - bbox[0])) / 2 y = (height - (bbox[3] - bbox[1])) / 2 draw.multiline_text( (x, y), wrapped, fill=(255, 255, 255), font=font, align="center" ) img.save(path) # FRONTEND (IM SELBEN SCRIPT) HTML = """ Instagram Generator

Instagram Text → Bild Generator


""" @app.route("/") def home(): return HTML @app.route("/generate", methods=["POST"]) def generate(): text = request.form["text"] folder = datetime.now().strftime("%Y%m%d%H%M%S") folder_path = os.path.join(OUTPUT_DIR, folder) os.makedirs(folder_path, exist_ok=True) chunks = split_text(text) files = [] for i, chunk in enumerate(chunks): file_path = os.path.join(folder_path, f"post_{i+1}.png") create_image(chunk, file_path) files.append(file_path) zip_path = os.path.join(OUTPUT_DIR, f"{folder}.zip") with zipfile.ZipFile(zip_path, "w") as zipf: for f in files: zipf.write(f, os.path.basename(f)) return send_file(zip_path, as_attachment=True) if __name__ == "__main__": app.run(debug=True)

Kommentare

Beliebte Posts aus diesem Blog

gg

c