Created
October 25, 2025 14:04
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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