mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 04:19:19 -08:00
feat: OCR???
This commit is contained in:
parent
1071288f6e
commit
71383c5b5b
6 changed files with 69 additions and 2 deletions
65
home/profiles/graphical/ocr.nix
Normal file
65
home/profiles/graphical/ocr.nix
Normal file
|
|
@ -0,0 +1,65 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
home.packages = let
|
||||||
|
inherit (lib.meta) getExe;
|
||||||
|
ocr = pkgs.writeShellScriptBin "ocr" ''
|
||||||
|
set -euo pipefail
|
||||||
|
pushd () {
|
||||||
|
command pushd "$@" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
popd () {
|
||||||
|
command popd "$@" > /dev/null
|
||||||
|
}
|
||||||
|
args="$(getopt -a -o r: --long rotate: -- "$@")"
|
||||||
|
|
||||||
|
ROTATE=""
|
||||||
|
FORMAT="jpg"
|
||||||
|
|
||||||
|
usage(){
|
||||||
|
cat <<EOF
|
||||||
|
$0 - OCR helper, uses ocrmypdf which uses Tesseract OCR under the hood!
|
||||||
|
Usage: $0 <file>
|
||||||
|
[ -r input | --rotate input ]: Angle to rotate the image by
|
||||||
|
[ -f input | --format input ]: Intermediary format, defaults to jpg
|
||||||
|
EOF
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ $# -eq 0 ]; then
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
eval set -- "''${args}"
|
||||||
|
while :
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
-r | --rotate) ROTATE="$2" ; shift 2 ;;
|
||||||
|
-f | --format) ROTATE="$2" ; shift 2 ;;
|
||||||
|
--) shift; break ;;
|
||||||
|
*) >&2 echo Unsupported option: $1
|
||||||
|
usage ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
INTERMEDIARY="./image.''${FORMAT}"
|
||||||
|
pushd $(mktemp -d)
|
||||||
|
if [ -n "''${ROTATE}" ]; then
|
||||||
|
${getExe pkgs.imagemagick} $1 -rotate "''${ROTATE}" "''${INTERMEDIARY}"
|
||||||
|
else
|
||||||
|
${getExe pkgs.imagemagick} $1 "''${INTERMEDIARY}"
|
||||||
|
fi
|
||||||
|
${getExe pkgs.ocrmypdf} -q --rotate-pages-threshold 2.0 --clean --output-type=none \
|
||||||
|
--sidecar tmp.txt --rotate-pages --image-dpi 300 --deskew --output-type pdfa --jobs 4 \
|
||||||
|
"''${INTERMEDIARY}" - > /dev/null
|
||||||
|
printf "%s" "$(< tmp.txt)"
|
||||||
|
popd
|
||||||
|
'';
|
||||||
|
in [
|
||||||
|
ocr
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -23,6 +23,7 @@ in {
|
||||||
vimAlias = true;
|
vimAlias = true;
|
||||||
viAlias = true;
|
viAlias = true;
|
||||||
plugins = with pkgs.vimPlugins; [
|
plugins = with pkgs.vimPlugins; [
|
||||||
|
nvim-lspconfig
|
||||||
# Libraries
|
# Libraries
|
||||||
plenary-nvim
|
plenary-nvim
|
||||||
# Disables and re-enables highlighting when searching
|
# Disables and re-enables highlighting when searching
|
||||||
|
|
|
||||||
|
|
@ -361,3 +361,4 @@ end, {remap=true})
|
||||||
vim.keymap.set("", "F", function()
|
vim.keymap.set("", "F", function()
|
||||||
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true })
|
hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true })
|
||||||
end, {remap=true})
|
end, {remap=true})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
asciinema
|
asciinema
|
||||||
bandwhich
|
bandwhich
|
||||||
pciutils
|
pciutils
|
||||||
bingrep
|
|
||||||
chafa
|
chafa
|
||||||
dust
|
dust
|
||||||
eva
|
eva
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
jmtpfs
|
jmtpfs
|
||||||
dnsutils
|
dnsutils
|
||||||
usbutils
|
usbutils
|
||||||
|
imagemagick
|
||||||
];
|
];
|
||||||
services.udev.packages = [
|
services.udev.packages = [
|
||||||
pkgs.android-udev-rules
|
pkgs.android-udev-rules
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ _: let
|
||||||
konawall-py.settings = {
|
konawall-py.settings = {
|
||||||
source = "konachan";
|
source = "konachan";
|
||||||
tags = [
|
tags = [
|
||||||
"rating:-e"
|
"-rating:e"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
# konawall-py.settings = {
|
# konawall-py.settings = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue