mirror of
https://github.com/Dadido3/Scanyonero.git
synced 2025-06-06 01:10:00 +00:00
- Rename to Scanyonero - Add FTP server that ingests TIFF, PNG, JPEG or PDF files - Add web interface to check and modify ingested files - Rework how ocrmypdf is invoked Basics are working, but the program is not in a usable state.
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package document
|
|
|
|
import (
|
|
"Scanyonero/unit"
|
|
"regexp"
|
|
)
|
|
|
|
type IngestorRule struct {
|
|
// All entries that are non nil have to match.
|
|
Match struct {
|
|
Name *regexp.Regexp // When this regular expression matches with the filename/filepath then the rule is used.
|
|
XPixels *int // When the scanned image width in pixels matches with the given amount of pixels, the rule is used.
|
|
YPixels *int // When the scanned image height in pixels matches with the given amount of pixels, the rule is used.
|
|
}
|
|
|
|
// All non nil entries will be applied to the document pages.
|
|
Action struct {
|
|
MediumWidth *unit.Millimeter // Sets the width of the medium.
|
|
MediumHeight *unit.Millimeter // Sets the height of the medium.
|
|
ScanOffsetX *unit.Millimeter // Offsets the scan in the medium on the x axis.
|
|
ScanOffsetY *unit.Millimeter // Offsets the scan in the medium on the y axis.
|
|
}
|
|
}
|
|
|
|
// Apply will check and apply the rule per ingested page.
|
|
func (rule IngestorRule) Apply(ingestor Ingestor, file File, page *Page) error {
|
|
// Match.
|
|
|
|
if rule.Match.Name != nil && !rule.Match.Name.MatchString(file.Name) {
|
|
return nil
|
|
}
|
|
imageBounds := page.Image.Bounds()
|
|
if rule.Match.XPixels != nil && *rule.Match.XPixels != imageBounds.Dx() {
|
|
return nil
|
|
}
|
|
if rule.Match.YPixels != nil && *rule.Match.YPixels != imageBounds.Dy() {
|
|
return nil
|
|
}
|
|
|
|
// Apply actions.
|
|
|
|
if rule.Action.MediumWidth != nil {
|
|
page.Dimensions.MediumSize.X = *rule.Action.MediumWidth
|
|
}
|
|
if rule.Action.MediumHeight != nil {
|
|
page.Dimensions.MediumSize.Y = *rule.Action.MediumHeight
|
|
}
|
|
if rule.Action.ScanOffsetX != nil {
|
|
page.Dimensions.ScanSize.Origin.X = *rule.Action.ScanOffsetX
|
|
}
|
|
if rule.Action.ScanOffsetY != nil {
|
|
page.Dimensions.ScanSize.Origin.Y = *rule.Action.ScanOffsetY
|
|
}
|
|
|
|
return nil
|
|
}
|