Skip to content

Best config for OCR-ready PNGs #4365

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hymair opened this issue Apr 7, 2025 · 0 comments
Open

Best config for OCR-ready PNGs #4365

hymair opened this issue Apr 7, 2025 · 0 comments
Labels

Comments

@hymair
Copy link

hymair commented Apr 7, 2025

Question about an existing feature

What are you trying to achieve?

We are trying to achieve the best possible (most accurate) OCR results. Images will be of invoices and receipts taken by users with their phones mostly.

We want to downscale unnecessary large images and try to reduce AI token usage by sending less pixels.

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question

Current config:

export async function optimizeImage(buffer: Buffer): Promise<Buffer> {
    const processedBuffer = await sharp(buffer)
        .rotate()
        .resize({
            width: 2000,
            height: 2000,
            withoutEnlargement: true,
            fit: 'inside',
        })
        .grayscale()
        .normalise()
        .sharpen({
            sigma: 1.2,
            m1: 0.5,
            m2: 0.5,
        })
        .png()
        .toBuffer()

    return processedBuffer
}
@hymair hymair added the question label Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant