You can edit the below JavaScript code to customize the image tool.
Apply Changes
/**
* Movie Company and Year Image Scanner Identifier
* Scans an image for text using OCR to identify a movie company and a release year.
*
* @param {HTMLImageElement} originalImg - The original image to be processed
* @param {string} language - English by default ('eng')
* @returns {Promise<HTMLCanvasElement>} - A promise that resolves to a Canvas containing the result
*/
async function processImage(originalImg, language = "eng") {
// Canvas setup
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
const width = originalImg.width;
const height = originalImg.height;
// UI Panel config
const textPanelHeight = 140;
const minWidth = 600;
const canvasWidth = Math.max(width, minWidth);
const canvasHeight = height + textPanelHeight;
canvas.width = canvasWidth;
canvas.height = canvasHeight;
// 1. Draw the background
ctx.fillStyle = '#0a0a0a';
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
// 2. Draw the original image centered horizontally
const imgX = (canvasWidth - width) / 2;
ctx.drawImage(originalImg, imgX, 0, width, height);
// 3. Draw "Scanner" aesthetic overlays (cyan corners over the image)
ctx.strokeStyle = "#00ffcc";
ctx.lineWidth = 4;
const padding = Math.min(20, width * 0.1, height * 0.1);
const len = Math.min(40, width * 0.2, height * 0.2);
// Top-left
ctx.beginPath(); ctx.moveTo(imgX + padding, padding + len); ctx.lineTo(imgX + padding, padding); ctx.lineTo(imgX + padding + len, padding); ctx.stroke();
// Top-right
ctx.beginPath(); ctx.moveTo(imgX + width - padding - len, padding); ctx.lineTo(imgX + width - padding, padding); ctx.lineTo(imgX + width - padding, padding + len); ctx.stroke();
// Bottom-left
ctx.beginPath(); ctx.moveTo(imgX + padding, height - padding - len); ctx.lineTo(imgX + padding, height - padding); ctx.lineTo(imgX + padding + len, height - padding); ctx.stroke();
// Bottom-right
ctx.beginPath(); ctx.moveTo(imgX + width - padding - len, height - padding); ctx.lineTo(imgX + width - padding, height - padding); ctx.lineTo(imgX + width - padding, height - padding - len); ctx.stroke();
// 4. Load Tesseract.js dynamically for OCR
if (typeof window.Tesseract === 'undefined') {
await new Promise((resolve, reject) => {
const script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/tesseract.js@4/dist/tesseract.min.js';
script.crossOrigin = 'anonymous';
script.onload = () => resolve();
script.onerror = () => reject(new Error('Failed to load Tesseract.js'));
document.head.appendChild(script);
});
}
let foundYear = "None identified";
let foundCompany = "None identified";
let rawResultText = "";
try {
// Run OCR Engine on the original image
const result = await window.Tesseract.recognize(originalImg, language);
const text = result.data.text || "";
rawResultText = text.replace(/\n\s*\n/g, ' ').replace(/\s+/g, ' ').trim();
// Regex to find a standard movie release year (1880 - 2099)
const yearRegex = /\b(18[8-9]\d|19\d{2}|20[0-2]\d)\b/g;
const years = text.match(yearRegex);
if (years && years.length > 0) {
foundYear = years[0];
}
// Expanded list of popular production companies (ordered roughly by specificity)
const companies = [
"20th Century Fox", "Twentieth Century Fox", "Warner Bros", "Universal Pictures",
"Paramount Pictures", "Walt Disney", "Sony Pictures", "Columbia Pictures",
"Metro-Goldwyn-Mayer", "New Line Cinema", "DreamWorks", "Miramax",
"Lionsgate", "Pixar", "Marvel Studios", "Lucasfilm", "A24", "Legendary",
"TriStar", "Orion", "RKO", "United Artists", "Amblin", "Touchstone",
"Universal", "Paramount", "Disney", "Columbia", "Sony", "Fox", "MGM"
];
// Normalize OCR text (remove spaces/punctuation for a robust inner-match)
const normalizedText = text.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
for (let comp of companies) {
const normalizedComp = comp.replace(/[^a-zA-Z0-9]/g, '').toUpperCase();
if (normalizedText.includes(normalizedComp)) {
foundCompany = comp;
break;
}
}
} catch (err) {
console.error("Scanner Identifier Error:", err);
foundCompany = "Error reading image";
foundYear = "Error";
}
// 5. Draw Results Panel
const panelY = height;
// Panel Background
ctx.fillStyle = "#1a1a1a";
ctx.fillRect(0, panelY, canvasWidth, textPanelHeight);
// Subtle neon border separator
ctx.fillStyle = "#00ffcc";
ctx.fillRect(0, panelY, canvasWidth, 2);
// Panel Typography
ctx.font = "bold 22px Arial, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "top";
// Panel Header
ctx.fillStyle = "#ffffff";
ctx.fillText("SCANNER IDENTIFIER RESULTS", 30, panelY + 15);
// Data - Company
ctx.font = "bold 18px Arial, sans-serif";
ctx.fillStyle = "#00ffcc";
ctx.fillText(`Production Company : ${foundCompany}`, 30, panelY + 55);
// Data - Year
ctx.fillStyle = "#ffcc00";
ctx.fillText(`Release Year : ${foundYear}`, 30, panelY + 85);
// Show raw string preview if nothing gracefully identified
if (foundCompany === "None identified" && rawResultText.length > 0) {
ctx.fillStyle = "#888888";
ctx.font = "italic 14px Arial, sans-serif";
let displayRaw = rawResultText;
if (displayRaw.length > 70) displayRaw = displayRaw.substring(0, 67) + '...';
ctx.fillText(`Raw text segment: "${displayRaw}"`, 30, panelY + 115);
}
return canvas;
}
Apply Changes