Skip to content

Instantly share code, notes, and snippets.

@veteran29
Created February 19, 2023 13:29
Show Gist options
  • Save veteran29/4c975afee00b2a9012ce414210ef1ea9 to your computer and use it in GitHub Desktop.
Save veteran29/4c975afee00b2a9012ce414210ef1ea9 to your computer and use it in GitHub Desktop.
OCR
@echo off
rem the name of the script is drive path name of the Parameter %0
rem (= the batch file) but with the extension ".ps1"
set PSScript=%~dpn0.ps1
set args=%1
:More
shift
if '%1'=='' goto Done
set args=%args%, %1
goto More
:Done
powershell.exe -NoExit -Command "& '%PSScript%' '%args%'"
$files = $args[0].Split(',') | % {$_.Trim()}
$threshold = '55%'
foreach ($file in $files) {
Write-Host "Converting $file"
magick convert $file `
-type Grayscale -threshold $threshold `
-define connected-components:area-threshold=3 `
-define connected-components:mean-color=true `
-connected-components 8 `
"$file.png"
}
Write-Host "`nFiles converted"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment