Skip to content

Instantly share code, notes, and snippets.

@La5u
Created October 25, 2025 14:04
Show Gist options
  • Select an option

  • Save La5u/edfdfd0ae54f1cbd57301c56dee2b7c9 to your computer and use it in GitHub Desktop.

Select an option

Save La5u/edfdfd0ae54f1cbd57301c56dee2b7c9 to your computer and use it in GitHub Desktop.
extract text from image in clipboard, and overwrite the clipboard with OCR (using tesseract)
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$image = [Windows.Forms.Clipboard]::GetImage()
if ($image) {
$tmp = [IO.Path]::Combine($env:TEMP, "clip_ocr.png")
$image.Save($tmp, [System.Drawing.Imaging.ImageFormat]::Png)
$tesseract = "C:\Program Files\Tesseract-OCR\tesseract.exe"
$tmpBase = [IO.Path]::Combine($env:TEMP, "clip_ocr_" + [IO.Path]::GetRandomFileName())
& "$tesseract" $tmp $tmpBase -l eng+rus+fra 2>$null
$text = Get-Content -Raw -Encoding UTF8 ($tmpBase + ".txt")
Remove-Item $tmp, ($tmpBase + ".txt") -ErrorAction SilentlyContinue
if ($text.Trim()) {
Set-Clipboard -Value $text
[console]::beep(200,300)
Write-Host "✅ OCR text copied to clipboard."
} else {
Write-Host "⚠️ No text detected."
}
} else {
Write-Host "⚠️ No image found in clipboard."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment