Please bookmark this page to avoid losing your image tool!

Image Text Search And Processing Tool

(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, searchText = "", highlightColor = "rgba(255, 255, 0, 0.5)", matchCase = "false") {
    // Create canvas and draw the original image
    const canvas = document.createElement('canvas');
    canvas.width = originalImg.width;
    canvas.height = originalImg.height;
    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0);

    // If no search text is provided, return the original image canvas
    if (!searchText || searchText.trim() === "") {
        return canvas;
    }

    // Dynamically load Tesseract.js (Optical Character Recognition library)
    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);
        });
    }

    try {
        // Initialize the Tesseract worker
        const worker = await Tesseract.createWorker('eng');
        
        // Process the image canvas to extract words and bounding boxes
        const { data } = await worker.recognize(canvas);
        await worker.terminate();

        const isCaseSensitive = (matchCase === "true" || matchCase === "1");
        const sText = isCaseSensitive ? searchText.trim() : searchText.trim().toLowerCase();
        const searchTarget = sText.split(/\s+/); // Handle multi-word search phrases
        const ocrWords = data.words;

        if (ocrWords && ocrWords.length > 0) {
            // Iterate over all extracted word lists
            for (let i = 0; i <= ocrWords.length - searchTarget.length; i++) {
                let match = true;
                
                // Compare OCR words against our search targets
                for (let j = 0; j < searchTarget.length; j++) {
                    let wText = ocrWords[i + j].text;
                    if (!isCaseSensitive) wText = wText.toLowerCase();
                    
                    let sWord = searchTarget[j];
                    
                    // Simple cleaning for robust matching ignoring errant punctuation
                    let wClean = wText.replace(/[^a-zA-Z0-9]/g, "");
                    let sClean = sWord.replace(/[^a-zA-Z0-9]/g, "");

                    // We declare a match if the target exists as a substring of either raw or cleaned text
                    if (!wText.includes(sWord) && (!wClean || !wClean.includes(sClean))) {
                        match = false;
                        break;
                    }
                }

                // If match is found, draw a highlighting bounding box spanning all matched words
                if (match) {
                    let x0 = Math.min(...searchTarget.map((_, idx) => ocrWords[i + idx].bbox.x0));
                    let y0 = Math.min(...searchTarget.map((_, idx) => ocrWords[i + idx].bbox.y0));
                    let x1 = Math.max(...searchTarget.map((_, idx) => ocrWords[i + idx].bbox.x1));
                    let y1 = Math.max(...searchTarget.map((_, idx) => ocrWords[i + idx].bbox.y1));

                    ctx.fillStyle = highlightColor;
                    ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
                }
            }
        }
    } catch (err) {
        console.error("Error processing Image Search OCR:", err);
        ctx.fillStyle = "rgba(255, 0, 0, 0.7)";
        ctx.font = "bold 24px sans-serif";
        ctx.fillText("OCR Text Search Failed", 20, 40);
    }

    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 Text Search and Processing Tool uses Optical Character Recognition (OCR) technology to identify and locate specific text within an image. Once text is detected, the tool can highlight the matching words or phrases with a customizable color overlay, allowing users to visually pinpoint information. This tool is useful for quickly scanning documents, receipts, or screenshots to find specific keywords, making it easier to navigate through scanned files or digital images containing large amounts of text.

Leave a Reply

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