Skip to content

Instantly share code, notes, and snippets.

@pr3sidentspence
Created December 3, 2018 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pr3sidentspence/f08468de81f00785f6a9f60335d73408 to your computer and use it in GitHub Desktop.
Save pr3sidentspence/f08468de81f00785f6a9f60335d73408 to your computer and use it in GitHub Desktop.
Uses cropper function from findDocsInScanAndSeparate.ps1 but feeds it static coordinates, for when we used the templated scanning.
function chopper {
Get-ChildItem $PSScriptRoot -Filter *.jpg |
Foreach-Object {
[System.Collections.ArrayList]$gapInfo = @()
$gapInfo += $_
$gapInfo += 96
$gapInfo += 96
$gapInfo += 106
$gapInfo += 2379
$gapInfo += 133
$gapInfo += 4680
$gapInfo += 74
$gapInfo += 7015
cropper($gapInfo)
}
}
function cropper {
$fileName = $gapInfo[0]
Write-Host The arraylist has $gapInfo.Count values.
# The arraylist has one entry for the filename, and two for each gap, there is always 1 more
# gap than there are cards. So starting with arraylist.Count (e.g. 9) take 1 off for the name (8)
# and 2 off for the extra gap info (6), divide by two to get number of cards.
$numCards = ($gapInfo.Count - 3) / 2
Write-Host That means the scan should have $numCards cards
for ($i = 0; $i -lt (2 * $numCards); $i = $i + 2) {
$overGapEnd = $gapInfo[($i + 2)] - 10
$overGapStart = $overGapEnd - $gapInfo[($i + 1)] + 10
$underGapEnd = $gapInfo[($i + 4)] - 10
$height = $underGapEnd - $overGapStart
Write-Host crop from y $overGapStart to $underGapEnd for a height of $height
# The 3600 below worked for this batch of cards, and probably most postcards.
$cropParams = "3600x$height+0+$overGapStart"
$position = $i / 2 + 1
#Write-Host position is $position
if ($fileName -match ("(B.{1,3})\-([0-9][0-9][0-9])\-([0-9][0-9][0-9])\-([0-9][0-9][0-9])\-(.*)")) {
$keepPos = $position + 1
#Write-Host keepPos is $keepPos
$replace = "`$1-`$$keepPos-`$5"
#Write-Host replace is $replace
$outFileName = $fileName -replace ("(B.{1,3})\-([0-9][0-9][0-9])\-([0-9][0-9][0-9])\-([0-9][0-9][0-9])\-(.*)"), ($replace)
#Write-Host outFileName is $outFileName
}
$output = "$PSScriptRoot/output/$outFileName"
# Uncomment next line to see during process what it's sending to IM.
# Write-Host magick.exe $_ "-crop" $cropParams $output
& magick.exe $_ "-crop" $cropParams $output
}
}
chopper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment