Skip to content

Commit

Permalink
Documentation update, plus other minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim2266 committed Sep 7, 2019
1 parent 26577d5 commit b71cf13
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,38 @@ Options:

A wrapper around `tesseract` tool.

#### Image geometry calculator for cropping
```
▶ ./crop-geometry
Compose crop geometry string for "convert -crop"
Usage:
crop-geometry left right top bottom input-file-name
where
"left", "right", "top", and "bottom" (in this order) are percentages
of the image to crop from the respective sides of the image. The range of
values is from 0 to 99.99%, with up to 2 digits after the decimal point.
Example:
crop-geometry 19.33 2 3 40 input.pgm
```

The tool writes the composed geometry string to `stdout`. Can be used like:
```
convert input_file -crop "$(crop-geometry 10 10 10 10 input-file)" output_file
```

#### Image normaliser
```
▶ ./norm-image
Crop image to content, and then add white border 5% thick.
Usage:
norm-image input-file output-file
```

##### Platform: Linux

Tested on Linux Mint 18.1, will probably work on other Debian-based distributions.
Tested on Linux Mint 19.2, will probably work on other Debian-based distributions as well.



Expand Down
9 changes: 4 additions & 5 deletions crop-geometry
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ usage() {
Compose crop geometry string for "convert -crop"
Usage:
$(basename "$0") left% right% top% bottom% input-file-name
$(basename "$0") left right top bottom input-file-name
where
"left", "right", "top", and "bottom" (in this order) are percentages
of the image to crop from the respective sides of the image. The range of
values is from 0 to 99.99%, with up to 2 digits after the decimal point.
Percent symbol '%' is optional.
Example:
$(basename "$0") 19.33 2 3 40% input.pgm
$(basename "$0") 19.33 2 3 40 input.pgm
EOF
exit 1
}
Expand All @@ -63,7 +62,7 @@ read -r W H < <(identify -format "%w %h\n" "$5")

# read crop values
read_param() {
local -r VALID='^[0-9]{1,2}(\.[0-9]{,2})?%?$' # values from 0 to 99.99%
local -r VALID='^[0-9]{1,2}(\.[0-9]{,2})?$' # values from 0 to 99.99%

[[ "$2" =~ $VALID ]] || die "Invalid value for \"$1\": $2"

Expand All @@ -88,5 +87,5 @@ declare -r -i \
echo "$((W - L - R))x$((H - T - B))+$L+$T"

# Example command:
# convert input_file +repage -crop "$(crop-geometry 10 10 10 10 input-file)" +repage $output_file
# convert input_file +repage -crop "$(crop-geometry 10 10 10 10 input-file)" +repage output_file

3 changes: 1 addition & 2 deletions norm-image
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,4 @@ EOF
[ $# -eq 2 ] || usage

# normalise
exec convert "$1" -fuzz 2% -trim -bordercolor white -border 5%x5% +repage "$2"
exit # just in case
exec convert "$1" -fuzz 2% -trim -bordercolor white -border '5%x5%' +repage "$2"

0 comments on commit b71cf13

Please sign in to comment.