diff --git a/bin/extract-font.bat b/bin/extract-font.bat index db4d908..b14f206 100644 --- a/bin/extract-font.bat +++ b/bin/extract-font.bat @@ -6,5 +6,5 @@ if "%~1"=="" ( echo please give a directory in the in folder with .svg glyphs as input exit /b 1 ) -"%PICCREATE_PYTHON%" "%PICCREATE_LIBS%\glyphextract.py" -f %1 +"%PICCREATE_PYTHON%" "%PICCREATE_LIBS%\glyphextract.py" -i %1 -e %2 %3 %4 %5 %6 %7 %8 %9 exit /b %errorlevel% diff --git a/bin/extract-font.sh b/bin/extract-font.sh index 873bffa..6ef5546 100755 --- a/bin/extract-font.sh +++ b/bin/extract-font.sh @@ -1,9 +1,9 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" if [ -z "$1" ]; then echo "please give a directory in the in folder with .svg glyphs as input" exit 1 fi # Glyphen und .cfg eines Fonts nach $PICCREATE_OUT schreiben -python3 $PICCREATE_LIBS/glyphextract.py -f "$1" +python3 $PICCREATE_LIBS/glyphextract.py -i "$1" -e "${@:2}" diff --git a/bin/extract-glyph.sh b/bin/extract-glyph.sh index 3c86ce6..343362b 100755 --- a/bin/extract-glyph.sh +++ b/bin/extract-glyph.sh @@ -1,5 +1,5 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" # Einen Buchstaben extrahieren # extract-glyph.sh -i ../in/ausgangsschrift/a.svg Testbild fuer Inkscape diff --git a/bin/fonttest.bat b/bin/fonttest.bat index a25172f..9d568d8 100644 --- a/bin/fonttest.bat +++ b/bin/fonttest.bat @@ -6,5 +6,5 @@ if "%~1"=="" ( echo please give a directory in the in folder with .svg glyphs as input exit /b 1 ) -"%PICCREATE_PYTHON%" "%PICCREATE_LIBS%\glyphextract.py" -t %1 +"%PICCREATE_PYTHON%" "%PICCREATE_LIBS%\glyphextract.py" -i %1 %2 %3 %4 %5 %6 %7 %8 %9 exit /b %errorlevel% diff --git a/bin/fonttest.sh b/bin/fonttest.sh index e8664e5..87fe8f7 100755 --- a/bin/fonttest.sh +++ b/bin/fonttest.sh @@ -1,9 +1,9 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" if [ -z "$1" ]; then echo "please give a directory in the in folder with .svg glyphs as input" exit 1 fi # Testbilder aller Glyphen eines Fonts nach $PICCREATE_OUT schreiben -python3 $PICCREATE_LIBS/glyphextract.py -t "$1" +python3 $PICCREATE_LIBS/glyphextract.py -i "$1" "${@:2}" diff --git a/bin/piccreate b/bin/piccreate index 6d93e13..6fea474 100755 --- a/bin/piccreate +++ b/bin/piccreate @@ -1,5 +1,5 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" # Startet das Programm python3 $PICCREATE_LIBS/piccreate.py "$@" diff --git a/bin/setenv.sh b/bin/setenv.sh index 5631615..67034ea 100755 --- a/bin/setenv.sh +++ b/bin/setenv.sh @@ -4,7 +4,8 @@ if [ ! -z $PICCREATE ];then return 0 fi -export PICCREATE=~/develop/python/piccreate +# das Verzeichnis ueber bin/ +export PICCREATE=$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")/.." && pwd) echo setting environment to $PICCREATE # ------------------ diff --git a/bin/svgconvert.sh b/bin/svgconvert.sh index 13f3524..3e3f4b7 100755 --- a/bin/svgconvert.sh +++ b/bin/svgconvert.sh @@ -1,6 +1,6 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" # SVG Bilder mit ImageMagick in JPG/PNG umwandeln -# svgconvert.sh -c punkteraetsel --format png -p +# svgconvert.sh -c punkteraetsel -p python3 $PICCREATE_LIBS/svgconvert.py "$@" diff --git a/bin/webscan.sh b/bin/webscan.sh index 41f5892..5e635fe 100755 --- a/bin/webscan.sh +++ b/bin/webscan.sh @@ -1,5 +1,5 @@ #!/bin/bash -. setenv.sh +. "$(dirname "${BASH_SOURCE[0]}")/setenv.sh" # Vorschaubilder von Webseiten erzeugen (Playwright, Python-venv im Projekt) PYTHON=python3 diff --git a/doc/README.md b/doc/README.md index de32934..cf0c163 100644 --- a/doc/README.md +++ b/doc/README.md @@ -43,14 +43,37 @@ Alles läuft unter Linux und Windows, siehe [Windows](#windows). Alle Pfade werden über Umgebungsvariablen gefunden, die `bin/setenv.sh` setzt (`PICCREATE`, `PICCREATE_CFG`, `PICCREATE_IN`, `PICCREATE_OUT`, -`PICCREATE_FONTS`, `PICCREATE_BACKGROUNDS`, …). Der Installationspfad steht -dort fest auf `~/develop/python/piccreate`. +`PICCREATE_FONTS`, `PICCREATE_BACKGROUNDS`, …). Das Projektverzeichnis ermittelt +`setenv.sh` selbst (das Verzeichnis über `bin/`), die Skripte in `bin/` lassen +sich deshalb von überall aufrufen. Nur wer die Variablen in der eigenen Shell +braucht, lädt `setenv.sh` selbst (bash oder zsh): ```sh cd bin . ./setenv.sh ``` +## Gemeinsame Optionen + +Alle Programme benutzen für dieselbe Aufgabe denselben Schalter: + +| Option | Bedeutung | piccreate | svgconvert | webscan | glyphextract | +|---------------------|----------------------------------------------------|:-:|:-:|:-:|:-:| +| `-c`, `--config` | Konfiguration aus `cfg/` (Endung `.cfg` optional) | ✓ | ✓ | ✓ | | +| `-i`, `--infile` | Eingabe (CSV, URL-Liste, Glyph oder Font) | ✓ | ✓ | ✓ | ✓ | +| `-o`, `--outdir` | Ordner für die erzeugten Bilder (Standard `$PICCREATE_OUT`) | ✓ | ✓ | ✓ | ✓ | +| `--section` | Sektion der Konfiguration mit den Bildmaßen | | ✓ | ✓ | | +| `--format` | Bildformat `jpg` oder `png` (überschreibt die Konfiguration) | | ✓ | ✓ | | +| `-f`, `--force` | vorhandene Bilder überschreiben | | ✓ | ✓ | | +| `-j`, `--jobs` | Anzahl paralleler Jobs | | ✓ | ✓ | | +| `-t`, `--test` | Testbilder erzeugen | | ✓ | | | +| `-y`, `--dry` | Probelauf, keine Dateien schreiben | ✓ | ✓ | | | +| `-v`, `--verbose` | ausführliche Ausgabe | | ✓ | ✓ | | +| `-h`, `--help` | Hilfe | ✓ | ✓ | ✓ | ✓ | + +Ältere Namen funktionieren weiter: `--cfg` für `--config` und bei svgconvert +`--svgfolder` für `--outdir`. + ## Bilder erzeugen ```sh @@ -59,7 +82,7 @@ cd bin | Option | Bedeutung | |-------------------|------------------------------------------------------------| -| `-c`, `--cfg` | Konfiguration aus `cfg/` (Endung `.cfg` optional) | +| `-c`, `--config` | Konfiguration aus `cfg/` (Endung `.cfg` optional) | | `-i`, `--infile` | CSV-Datei aus `in/` (Endung `.csv` optional) | | `-o`, `--outdir` | Ausgabeverzeichnis (Standard: `$PICCREATE_OUT`) | | `-s`, `--startfrom` | Nummerierung bei jedem Wort / Großbuchstaben neu beginnen | @@ -129,22 +152,26 @@ Die Sektionen `[jpgs]`, `[png]` usw. beschreiben die Rastergrafiken für ## SVG in JPG/PNG umwandeln ```sh -./svgconvert.sh -c punkteraetsel --format png -p +./svgconvert.sh -c punkteraetsel -p ``` -Wandelt alle SVGs in `$PICCREATE_OUT` (oder `-s `) parallel mit -ImageMagick um. `--format` wählt die Sektion aus der Konfiguration. +Wandelt alle SVGs in `$PICCREATE_OUT` (oder `-o `) parallel mit +ImageMagick um; die Bilder landen im selben Ordner. Breite, Höhe, Format und +Auflösung kommen aus der Sektion `--section` der Konfiguration (Standard +`[png]`, für große JPGs z. B. `--section jpgs`). | Option | Bedeutung | |-----------------|--------------------------------------------------------| | `-c` | Konfiguration aus `cfg/` (Endung `.cfg` optional) | -| `--format` | Sektion/Format, z. B. `png` oder `jpgs` (Standard `jpg`) | +| `-o` | Ordner mit den SVGs, auch für die Bilder (Standard `$PICCREATE_OUT`) | +| `--section` | Sektion mit den Bildmaßen (Standard `png`) | +| `--format` | `jpg` oder `png` (überschreibt die Konfiguration) | | `-i` | CSV aus `in/` prüfen: fehlende Bilder melden, nur diese umwandeln | | `-j` | Anzahl paralleler Jobs (Standard 8) | | `-b` | Hintergrundfarbe, `none` für transparent | | `-f` | vorhandene Bilder überschreiben | | `-p` / `-v` | Fortschrittsbalken / ausführliche Ausgabe | -| `-s` | Ordner mit den SVGs (Standard `$PICCREATE_OUT`) | +| `-t ` | `n` Test-SVGs erzeugen und umwandeln | | `-y` | Probelauf ohne Umwandlung | ## Vorschaubilder von Webseiten (webscan) @@ -182,7 +209,7 @@ besser das Chromium der Distribution): ```sh sudo pacman -S chromium -export PICCREATE_BROWSER=/usr/bin/chromium # oder Option -b /usr/bin/chromium +export PICCREATE_BROWSER=/usr/bin/chromium # oder Option --browser /usr/bin/chromium ``` Fehlen Playwright oder der Browser, gibt `webscan.py` die passenden Befehle @@ -208,11 +235,12 @@ Aufruf: | `-c` | Konfiguration (Standard `webscan`) | | `-i` | Eingabedatei aus `in/` oder mit Pfad | | `-o` | Ausgabeverzeichnis (Standard `$PICCREATE_OUT`) | +| `--section` | Sektion mit den Bildmaßen (Standard `webscan`) | | `--format` | `jpg` oder `png` (überschreibt die Konfiguration) | | `-j` | Anzahl gleichzeitig geladener Seiten (Standard 4) | -| `-t` | Wartezeit pro Seite in Sekunden (Standard 20) | +| `--timeout` | Wartezeit pro Seite in Sekunden (Standard 20) | | `-f` | vorhandene Bilder überschreiben | -| `-b` | Pfad zu einem eigenen Chromium | +| `--browser` | Pfad zu einem eigenen Chromium | | `-v` | ausführliche Ausgabe | Seiten ohne URL oder mit Ladefehler werden übersprungen und am Ende @@ -248,8 +276,18 @@ Nummern als Text `x1`, `x2`, …): ./extract-glyph.sh -i ../in/ausgangsschrift/a.svg -e # nur ein Buchstabe ``` -Alle drei rufen `libs/glyphextract.py` auf (`-f`, `-t` bzw. `-i [-e]`) und -schreiben nach `$PICCREATE_OUT` (oder `-o `). Das Ergebnis +Alle drei rufen `libs/glyphextract.py` auf. Dort ist `-i` ein einzelner +Buchstabe oder ein Font (Ordner in `in/` oder Pfad); mit `-e` werden die +Glyphen für den Font extrahiert (bei einem Font zusätzlich `.cfg`), +ohne `-e` entstehen Testbilder zum Prüfen in Inkscape: + +```sh +python3 glyphextract.py -i ausgangsschrift -e # = extract-font.sh +python3 glyphextract.py -i ausgangsschrift # = fonttest.sh +python3 glyphextract.py -i ../in/ausgangsschrift/a.svg -e +``` + +Alle schreiben nach `$PICCREATE_OUT` (oder `-o `). Das Ergebnis (Glyph-SVGs und `.cfg`) wird anschließend nach `fonts//` übernommen. Werte wie `XSTEP` kann man danach in der `.cfg` noch von Hand anpassen. @@ -275,7 +313,7 @@ Beispiel: ```bat cd bin piccreate.bat -c punkteraetsel -i test -svgconvert.bat -c punkteraetsel --format png -p +svgconvert.bat -c punkteraetsel -p ``` Die `.bat`-Dateien nehmen das Python aus `.venv`, falls vorhanden, sonst den diff --git a/libs/glyphextract.py b/libs/glyphextract.py index d8bdb26..c9b1d3a 100644 --- a/libs/glyphextract.py +++ b/libs/glyphextract.py @@ -178,26 +178,26 @@ def main(): print('"' + out_dir + '" does not exist. Please give the directory for the output!') return 1 - if options.infile: + if os.path.isfile(options.infile): # ein Buchstabe (extract-glyph.sh) - if not os.path.isfile(options.infile) or not os.path.getsize(options.infile): - print('input file does not exist') + if not os.path.getsize(options.infile): + print('input file is empty') return 1 base, config = write_glyph(options.infile, out_dir, options.extract) with open(os.path.join(out_dir, base + '.cfg'), 'w', encoding='utf-8', newline='\n') as fh: fh.write(config) return 0 - name = options.font or options.test - source = font_source(name) + # alle Buchstaben eines Fonts + source = font_source(options.infile) configs = [] for svg_path in sorted_glyphs(source): - base, config = write_glyph(svg_path, out_dir, extract=bool(options.font)) + base, config = write_glyph(svg_path, out_dir, options.extract) print(base) configs.append((base, config)) - if options.font: - # ein Font (extract-font.sh): alle Sektionen in .cfg + if options.extract: + # Font (extract-font.sh): alle Sektionen in .cfg cfg_name = os.path.basename(os.path.normpath(source)) + '.cfg' with open(os.path.join(out_dir, cfg_name), 'w', encoding='utf-8', newline='\n') as fh: fh.write(''.join(config for _, config in configs)) @@ -211,36 +211,33 @@ def main(): if __name__ == '__main__': - parser = optparse.OptionParser(usage="""%prog [options] + parser = optparse.OptionParser(usage="""%prog -i [-e] [options] Example usage ------------- -one glyph, to test it later with inkscape: +one glyph, test picture to check it with inkscape: $ %prog -i ../in/ausgangsschrift/a.svg one glyph, extract the points and text for the font: $ %prog -i ../in/ausgangsschrift/a.svg -e -all glyphs of a font (directory in in/) including the font config: - $ %prog -f ausgangsschrift +all glyphs of a font (directory in in/ or a path) including the font config: + $ %prog -i ausgangsschrift -e test pictures of all glyphs of a font: - $ %prog -t ausgangsschrift + $ %prog -i ausgangsschrift """, version='%prog ' + __version__) parser.add_option("-i", "--infile", dest="infile", - help="svg file of one glyph") + help="svg file of one glyph or directory with the glyphs of a font") parser.add_option("-e", "--extract", dest="extract", action='store_true', default=False, - help="with -i: extract the glyph for the font instead of a test picture") - parser.add_option("-f", "--font", dest="font", - help="directory with the glyphs of a font: create glyphs and font config") - parser.add_option("-t", "--test", dest="test", - help="directory with the glyphs of a font: create test pictures") + help="extract the glyphs for the font (and write .cfg) " + "instead of test pictures") parser.add_option("-o", "--outdir", dest="outdir", default=os.environ.get('PICCREATE_OUT', '.'), - help="directory for the output. default is $PICCREATE_OUT") + help="directory where the files will be written. default is $PICCREATE_OUT") (options, args) = parser.parse_args() - if sum(1 for o in (options.infile, options.font, options.test) if o) != 1: - parser.error('please give exactly one of -i, -f or -t') + if not options.infile: + parser.error('please give a glyph or a font with -i') sys.exit(main()) # vim: set tw=80 ft=python ts=4 sw=4: diff --git a/libs/piccreate.py b/libs/piccreate.py index 22d2cae..148e755 100644 --- a/libs/piccreate.py +++ b/libs/piccreate.py @@ -370,20 +370,20 @@ Read Confg, create wakeup and scale this kind of jiffy box """, version='%prog ' + __version__) - parser.add_option("-c", "--cfg", dest="config", default="test", - help="name of the config file with the Name of the rows to be used.", + parser.add_option("-c", "--config", "--cfg", dest="config", default="test", + help="name of the config file in cfg/ with the lines to be written", metavar="CONFIG_FILE") parser.add_option("-i", "--infile", dest="infile", help="csv file with input of names/content", action='store') parser.add_option("-s", "--startfrom", dest="startfrom", - help="csv file with input of names/content", + help="start the numbering again at every word / capital letter", action='store_true') parser.add_option("-o", "--outdir", dest="outdir", default=os.path.expandvars('$PICCREATE_OUT'), - help="path to the directory where the maps will be generated", + help="directory where the pictures will be written. default is $PICCREATE_OUT", action='store') parser.add_option("-y", "--dry", dest="dry", - help="dont generate images. Just ask the coordinates and fill database.", action='store_true' ) + help="dont write files, print the svg instead", action='store_true' ) (options, args) = parser.parse_args() diff --git a/libs/svgconvert.py b/libs/svgconvert.py index bbd1e80..477bf6f 100644 --- a/libs/svgconvert.py +++ b/libs/svgconvert.py @@ -123,16 +123,14 @@ def main(): print('ImageMagick not found. Please install it (https://imagemagick.org).') return None #set the workpath and the default config - work_path = os.path.expandvars('$PICCREATE_OUT') - if options.svgfolder: - work_path = os.path.expandvars(options.svgfolder) + work_path = os.path.expandvars(options.outdir) if not os.path.exists(work_path): print('\"'+ work_path +'\" does not exist. Please give the name of the folder with the svg-files!') return None pic_config = { 'width' : '600', 'height' : '200', - 'format' : options.format, + 'format' : options.format or 'jpg', 'density' : '150', 'background' : 'white', 'folder' : work_path, @@ -162,7 +160,12 @@ def main(): config = configparser.RawConfigParser() config.read(config_path, encoding='utf-8') # fill the config - pic_config = dict(config.items(options.format)) + if not config.has_section(options.section): + print('section [' + options.section + '] is missing in ' + config_path) + return None + pic_config = dict(config.items(options.section)) + if options.format: + pic_config['format'] = options.format if options.background: pic_config['background'] = options.background elif 'background' in pic_config: @@ -221,14 +224,17 @@ Read Confg, create wakeup and scale this kind of jiffy box parser.add_option("-b", "--background", dest="background", help="set the backgroundcolor. 'none' for transparent", action='store') - parser.add_option("-c", "--config", dest="config", - help="config file with all data for jobs", + parser.add_option("-c", "--config", "--cfg", dest="config", + help="config file in cfg/ with the picture sizes", action='store') parser.add_option("-f", "--force", dest="force", default=False, - help="create the pictures, no matter if they alreads exist", + help="create the pictures, no matter if they already exist", action='store_true') - parser.add_option("--format", dest="format", default='jpg', - help="format of the picture", + parser.add_option("--section", dest="section", default='png', + help="section in the config file. default is png", + action='store') + parser.add_option("--format", dest="format", + help="jpg or png, overrides the config", action='store') parser.add_option("-i", "--infile", dest="infile", help="csv file with input of names/content", @@ -239,8 +245,10 @@ Read Confg, create wakeup and scale this kind of jiffy box parser.add_option("-p", "--progress", dest="progress", help="print a progression bar", action='store_true') - parser.add_option("-s", "--svgfolder", dest="svgfolder", - help="path to the folder with the svg-files", + parser.add_option("-o", "--outdir", "--svgfolder", dest="outdir", + default=os.path.expandvars('$PICCREATE_OUT'), + help="folder with the svg files, the pictures are written there too. " + "default is $PICCREATE_OUT", action='store') parser.add_option("-t", "--test", dest="test", help="number of default svg-files that will be created and tested", @@ -249,8 +257,7 @@ Read Confg, create wakeup and scale this kind of jiffy box help="print the status of the conversion", action='store_true') parser.add_option("-y", "--dry", dest="dry", - help="dont generate images. \ - just try if the conversion would success", + help="dont generate images, just try if the conversion would succeed", action='store_true') (options, args) = parser.parse_args() diff --git a/libs/webscan.py b/libs/webscan.py index 3c793c0..c4c2f9e 100644 --- a/libs/webscan.py +++ b/libs/webscan.py @@ -235,7 +235,7 @@ Screenshots of all urls in in/kunden.csv (lines: customerid;url): $ %prog -c webscan -i kunden """, version='%prog ' + __version__) - parser.add_option("-c", "--cfg", dest="config", default="webscan", + parser.add_option("-c", "--config", "--cfg", dest="config", default="webscan", help="config file with a [webscan] section (width, height, format)", metavar="CONFIG_FILE") parser.add_option("--section", dest="section", default="webscan", @@ -248,11 +248,11 @@ Screenshots of all urls in in/kunden.csv (lines: customerid;url): help="jpg or png, overrides the config") parser.add_option("-j", "--jobs", dest="jobs", default=4, help="number of pages loaded in parallel. default is 4") - parser.add_option("-t", "--timeout", dest="timeout", default=20, + parser.add_option("--timeout", dest="timeout", default=20, help="seconds to wait for a page. default is 20") parser.add_option("-f", "--force", dest="force", action='store_true', help="create the pictures, no matter if they already exist") - parser.add_option("-b", "--browser", dest="browser", + parser.add_option("--browser", dest="browser", default=os.environ.get('PICCREATE_BROWSER'), help="path to a chromium executable instead of the playwright one " "(default: $PICCREATE_BROWSER)")