Please bookmark this page to avoid losing your image tool!

Movie Scene Text Extractor From Image

(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.
async function processImage(originalImg, language = 'eng') {
    // Create the main container
    const container = document.createElement('div');
    container.style.fontFamily = 'system-ui, -apple-system, sans-serif';
    container.style.padding = '24px';
    container.style.border = '1px solid #e2e8f0';
    container.style.borderRadius = '10px';
    container.style.backgroundColor = '#f8fafc';
    container.style.color = '#1e293b';
    container.style.minHeight = '150px';
    container.style.maxWidth = '100%';
    container.style.wordBreak = 'break-word';
    container.style.boxShadow = '0 4px 6px -1px rgba(0, 0, 0, 0.05)';
    container.style.boxSizing = 'border-box';
    
    // Create the loading view
    const loadingContainer = document.createElement('div');
    loadingContainer.style.display = 'flex';
    loadingContainer.style.flexDirection = 'column';
    loadingContainer.style.alignItems = 'center';
    loadingContainer.style.justifyContent = 'center';
    loadingContainer.style.height = '100%';
    
    // Add CSS for spinner animation
    const style = document.createElement('style');
    style.innerHTML = `@keyframes custom-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }`;
    container.appendChild(style);
    
    const spinner = document.createElement('div');
    spinner.style.border = '4px solid #cbd5e1';
    spinner.style.borderTop = '4px solid #3b82f6';
    spinner.style.borderRadius = '50%';
    spinner.style.width = '36px';
    spinner.style.height = '36px';
    spinner.style.animation = 'custom-spin 1s linear infinite';
    spinner.style.marginBottom = '12px';
    
    const loadingText = document.createElement('div');
    loadingText.innerText = 'Initializing text extraction...';
    loadingText.style.fontWeight = '500';
    loadingText.style.fontSize = '1.1rem';
    loadingText.style.color = '#475569';
    
    loadingContainer.appendChild(spinner);
    loadingContainer.appendChild(loadingText);
    container.appendChild(loadingContainer);

    // Render image to a canvas for OCR processing
    const canvas = document.createElement('canvas');
    canvas.width = originalImg.width;
    canvas.height = originalImg.height;
    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0);

    // Function to run the OCR extraction asynchronously
    const runOCR = async () => {
        try {
            // Dynamically load Tesseract.js if not available
            if (typeof Tesseract === 'undefined') {
                await new Promise((resolve, reject) => {
                    const script = document.createElement('script');
                    script.src = 'https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js';
                    script.onload = resolve;
                    script.onerror = reject;
                    document.head.appendChild(script);
                });
            }

            // Run OCR with progress feedback
            const { data: { text } } = await Tesseract.recognize(
                canvas,
                language,
                { logger: m => {
                    if (m.status === 'recognizing text') {
                        loadingText.innerText = `Extracting text... ${Math.round(m.progress * 100)}%`;
                    } else if (m.status === 'loading tesseract core') {
                        loadingText.innerText = 'Loading OCR Engine...';
                    } else if (m.status === 'loading language traineddata') {
                        loadingText.innerText = 'Loading Language Data...';
                    } else if (m.status === 'initializing api') {
                        loadingText.innerText = 'Initializing API...';
                    } else {
                        loadingText.innerText = `Processing: ${m.status}...`;
                    }
                }}
            );

            // Once finished, remove the loading text and display the result
            container.innerHTML = '';
            
            const title = document.createElement('h3');
            title.innerText = 'Extracted Movie Scene Text:';
            title.style.marginTop = '0';
            title.style.marginBottom = '12px';
            title.style.fontSize = '1.25rem';
            title.style.color = '#0f172a';
            container.appendChild(title);
            
            if (text && text.trim()) {
                const textDisplay = document.createElement('div');
                textDisplay.style.whiteSpace = 'pre-wrap';
                textDisplay.style.backgroundColor = '#ffffff';
                textDisplay.style.padding = '16px';
                textDisplay.style.border = '1px solid #cbd5e1';
                textDisplay.style.borderRadius = '6px';
                textDisplay.style.lineHeight = '1.6';
                textDisplay.style.fontSize = '1rem';
                textDisplay.style.fontFamily = 'monospace';
                textDisplay.innerText = text.trim();
                container.appendChild(textDisplay);
            } else {
                const noText = document.createElement('div');
                noText.style.fontStyle = 'italic';
                noText.style.color = '#64748b';
                noText.style.padding = '10px 0';
                noText.innerText = 'No text or subtitles were found in this scene.';
                container.appendChild(noText);
            }
        } catch (err) {
            // Handle any OCR engine failure cleanly
            container.innerHTML = '';
            const errorMsg = document.createElement('div');
            errorMsg.style.color = '#ef4444';
            errorMsg.style.fontWeight = '500';
            errorMsg.innerText = 'Error occurred during text extraction: ' + err.message;
            container.appendChild(errorMsg);
        }
    };
    
    // Do not block the initial return of the container element
    runOCR();

    return container;
}

Free Image Tool Creator

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

Description

This tool uses Optical Character Recognition (OCR) technology to extract text from images, specifically optimized for identifying text or subtitles within movie scenes. It allows users to upload an image and automatically converts any visible written content into editable text format. This is useful for transcribing dialogue from screenshots, capturing information from film posters, or saving subtitles from video stills for research and archival purposes.

Leave a Reply

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