The issue is likely due to the animated GIF flashing frames or text distortion. To fix this, we need to:
- Extract the specific frame where "YVZSM" is clearly visible
- Preprocess the image to improve OCR accuracy
Here's how to do it:
Step 1: Split the GIF into Individual Frames
Use this free online tool to extract frames from the GIF:
Ezgif.com - Split GIF
- Go to the link above
- Upload your GIF or paste the Base64 string (they have a Base64 input option)
- Split into frames and look for the frame where "YVZSM" is fully visible
Step 2: Preprocess the Image (if needed)
If the text is still unclear, use these tools to enhance the image:
Step 3: Use This Improved HTML/JS Version
This version adds image inversion and contrast controls:
<!DOCTYPE html>
<html>
<head>
<title>Enhanced Base64 OCR</title>
<script src="https://unpkg.com/tesseract.js@2.1.0/dist/tesseract.min.js"></script>
<style>
body { font-family: Arial, sans-serif; max-width: 800px; margin: 20px auto; padding: 20px; }
textarea { width: 100%; height: 100px; margin: 10px 0; }
#result { white-space: pre-wrap; padding: 10px; border: 1px solid #ccc; min-height: 50px; }
button { padding: 10px 20px; background: #007bff; color: white; border: none; cursor: pointer; }
.controls { margin: 10px 0; }
</style>
</head>
<body>
<h1>Enhanced Base64 OCR</h1>
<p>Paste your Base64 string below:</p>
<textarea id="base64Input" placeholder="data:image/gif;base64,..."></textarea>
<div class="controls">
<label>Scale: <input type="number" id="scaleInput" value="3" min="1" max="5"></label>
<button onclick="processImage()">Extract Text</button>
</div>
<h3>OCR Result:</h3>
<div id="result"></div>
<script>
async function processImage() {
const base64Input = document.getElementById('base64Input').value;
const scale = parseInt(document.getElementById('scaleInput').value) || 3;
const resultDiv = document.getElementById('result');
try {
// Clean Base64 input
const base64Data = base64Input.replace(/^data:image\/.*;base64,/, '');
// Create image element
const img = new Image();
img.src = `data:image/gif;base64,${base64Data}`;
img.onload = async () => {
// Create canvas with enhanced processing
const canvas = document.createElement('canvas');
canvas.width = img.width * scale;
canvas.height = img.height * scale;
const ctx = canvas.getContext('2d');
// Draw image with scaling
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
// Get image data for processing
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
// Optional: Invert colors if text is light on dark background
// Uncomment if needed:
// invertImage(imageData.data);
// Put processed image back
ctx.putImageData(imageData, 0, 0);
// Perform OCR
const { data: { text } } = await Tesseract.recognize(
canvas,
'eng',
{
logger: m => console.log(m),
// Optional: Add custom Tesseract config
// tessedit_pageseg_mode: 7 // single text line
}
);
resultDiv.textContent = text.trim();
};
img.onerror = () => {
resultDiv.textContent = "⚠️ Error loading image. Check Base64 format.";
};
} catch (error) {
resultDiv.textContent = `Error: ${error.message}`;
}
}
// Optional image inversion function
function invertImage(data) {
for (let i = 0; i < data.length; i += 4) {
data[i] = 255 - data[i]; // Red
data[i + 1] = 255 - data[i + 1]; // Green
data[i + 2] = 255 - data[i + 2]; // Blue
}
}
</script>
</body>
</html>
Key Improvements:
- Higher Scale Factor (3x default) - Captures more detail
- Optional Color Inversion - Uncomment the
invertImage() call if text is light-colored
- Tesseract Configuration Options - Try uncommenting
tessedit_pageseg_mode: 7 if text is a single line
If Still Not Working:
- Try different scale values (2-5)
- Use the frame extraction method first to isolate the best frame
- Check if the text is using a non-standard font (try different Tesseract languages in the config)
Would you like me to help analyze a specific frame if you share its Base64?