Please bookmark this page to avoid losing your image tool!

Image From Text Prompt Generator

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
function processImage(originalImg, prompt = "Детская площадка, Интересная книга, Паук", width = 512, height = 512, seed = -1) {
    const canvas = document.createElement('canvas');
    
    // Parse dimensions and clamp to reasonable API limits (max 1024x1024)
    canvas.width = Math.min(Math.max(parseInt(width) || 512, 64), 1024);
    canvas.height = Math.min(Math.max(parseInt(height) || 512, 64), 1024);
    const ctx = canvas.getContext('2d');
    
    // Draw initial loading state
    ctx.fillStyle = "#2c2f33";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    
    ctx.fillStyle = "#ffffff";
    ctx.font = "bold 20px Arial, sans-serif";
    ctx.textAlign = "center";
    ctx.textBaseline = "middle";
    ctx.fillText("Generating image...", canvas.width / 2, canvas.height / 2 - 15);
    
    ctx.fillStyle = "#aaaaaa";
    ctx.font = "italic 14px Arial, sans-serif";
    let displayPrompt = prompt.length > 40 ? prompt.substring(0, 37) + "..." : prompt;
    ctx.fillText(`Prompt: "${displayPrompt}"`, canvas.width / 2, canvas.height / 2 + 15);

    // AI Generation Configuration
    // Use pollinations.ai for free text-to-image API generation
    const actualSeed = parseInt(seed) === -1 ? Math.floor(Math.random() * 9999999) : parseInt(seed);
    const encodedPrompt = encodeURIComponent(prompt);
    const url = `https://image.pollinations.ai/prompt/${encodedPrompt}?width=${canvas.width}&height=${canvas.height}&seed=${actualSeed}&nologo=true`;

    // Fetch the dynamically generated image asynchronously
    fetch(url)
        .then(response => {
            if (!response.ok) {
                throw new Error(`API generated an error. Status: ${response.status}`);
            }
            return response.blob();
        })
        .then(blob => {
            const objectUrl = URL.createObjectURL(blob);
            const img = new Image();
            img.crossOrigin = "Anonymous";
            
            img.onload = () => {
                ctx.clearRect(0, 0, canvas.width, canvas.height);
                ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
                URL.revokeObjectURL(objectUrl);
            };
            
            img.onerror = () => {
                drawError(ctx, canvas.width, canvas.height, "Failed to load generated image data.");
                URL.revokeObjectURL(objectUrl);
            };
            
            img.src = objectUrl;
        })
        .catch(err => {
            drawError(ctx, canvas.width, canvas.height, "Error generating image.");
            console.error("Text to Image Generation failed:", err);
        });

    // Helper function to draw an error state on the canvas
    function drawError(context, w, h, msg) {
        context.fillStyle = "#4a1919";
        context.fillRect(0, 0, w, h);
        context.fillStyle = "#ff9999";
        context.font = "16px Arial, sans-serif";
        context.textAlign = "center";
        context.textBaseline = "middle";
        context.fillText(msg, w / 2, h / 2 - 10);
        context.font = "12px Arial, sans-serif";
        context.fillText("Please try a different prompt or try again later.", w / 2, h / 2 + 15);
    }

    // Return canvas immediately so it can be appended, allowing user to see loading indicator
    return canvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

The Image From Text Prompt Generator is an AI-powered tool that creates custom images based on written descriptions. By providing a text prompt, users can generate unique visuals in various dimensions. This tool is useful for creators looking to quickly visualize concepts, generate unique assets for digital projects, or produce artistic imagery for presentations and social media.

Leave a Reply

Your email address will not be published. Required fields are marked *