svgconvert.sh ruft svgconvert.py auf, generationlib entfernt
- bin/svgconvert.sh ist jetzt ein Wrapper wie svgconvert.bat (gleiche Optionen unter Linux und Windows) - svgconvert.py: Endung .cfg/.csv bei -c/-i optional - bin/generationlib (nur von svgconvert.sh benutzt) entfernt - doc/README.md angepasst Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
29c066b45a
commit
28f2bcdb32
@@ -1,151 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
NUM=0
|
|
||||||
QUEUE=""
|
|
||||||
MAX_NPROC=2 # default
|
|
||||||
REPLACE_CMD=0 # no replacement by default
|
|
||||||
|
|
||||||
USAGE="A simple wrapper for generating jpg pictures out of svg-files in parallel.
|
|
||||||
Usage: `basename $0` [-h] [-i] [-j nb_jobs] command arg_list
|
|
||||||
-h Shows this help
|
|
||||||
-c give the path to the cfg file
|
|
||||||
-i give the path of the svg files without the last /
|
|
||||||
-k check if the jpg already exist
|
|
||||||
-b set the background to transparent
|
|
||||||
-s set the sleeptime while there are too many simultanious jobs
|
|
||||||
-j Set number of simultanious jobs. Default is 2
|
|
||||||
-o directory where the files should be moved to after creation.
|
|
||||||
Default ist PICCREATE_OUT
|
|
||||||
Examples:
|
|
||||||
`basename $0` -i file -c config
|
|
||||||
`basename $0` -j 3 -i file -c config"
|
|
||||||
|
|
||||||
function cfg_parser {
|
|
||||||
INI_FILE=$1
|
|
||||||
SECTION=$2
|
|
||||||
eval `sed -n -e "/^\[$SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}" < $INI_FILE`
|
|
||||||
}
|
|
||||||
function get_filepath {
|
|
||||||
# probiere alle möglichen Kombinationen wo das file stehen könnte je
|
|
||||||
# nachdem ob es mit oder ohne Endung, mit oder ohne den Komplettpfad
|
|
||||||
# gegeben wurde
|
|
||||||
FILENAME=$1
|
|
||||||
ENDING=$2
|
|
||||||
DEFAULT_DIR=$3
|
|
||||||
if [ -s $FILENAME ] ; then
|
|
||||||
echo $FILENAME
|
|
||||||
elif [ -s $FILENAME.$ENDING ] ; then
|
|
||||||
echo "$FILENAME.$ENDING"
|
|
||||||
elif [ -s $DEFAULT_DIR/$FILENAME ] ; then
|
|
||||||
echo "$DEFAULT_DIR/$FILENAME"
|
|
||||||
elif [ -s $DEFAULT_DIR/$FILENAME.$ENDING ] ; then
|
|
||||||
echo "$DEFAULT_DIR/$FILENAME.$ENDING"
|
|
||||||
fi
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# Funktion die auf globalen Parametern beruht.
|
|
||||||
# überprüft ob alle notwendigen Angaben vorhanden sind
|
|
||||||
function check_params {
|
|
||||||
if [ -z "$INPUT_FILENAME" ]; then
|
|
||||||
echo "please give input file with -i."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ -z "$CFG_FILENAME" ]; then
|
|
||||||
echo "please give config file with -c."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
INPUT_FILE=`get_filepath $INPUT_FILENAME 'csv' $PICCREATE_WORK`
|
|
||||||
if [ ! -s $INPUT_FILE ] ; then
|
|
||||||
echo "-> input filename does not exist"
|
|
||||||
print "given was: -$INPUT_FILENAME-"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
CFG_PATH=`get_filepath $CFG_FILENAME 'cfg' $PICCREATE_CFG`
|
|
||||||
if [ ! -s $CFG_PATH ]; then
|
|
||||||
echo "-> config file with this name does not exist."
|
|
||||||
print "given was: -$CFG_FILENAME-"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
cfg_parser $CFG_PATH "$SECTION_NAME"
|
|
||||||
echo 'using width '$width
|
|
||||||
echo 'using height '$height
|
|
||||||
if [ -z "$width" ]; then
|
|
||||||
echo "please give width=xxx in section [$SECTION_NAME] in config $CFG_FILENAME."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
if [ -z "$height" ]; then
|
|
||||||
echo "please give height=xxx in section [$SECTION_NAME] in config $CFG_FILENAME."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# parse command line
|
|
||||||
if [ $# -eq 0 ]; then # must be at least one arg
|
|
||||||
echo "$USAGE" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
CHECKFILE=0
|
|
||||||
SLEEPTIME=0.5
|
|
||||||
BACKGROUND=''
|
|
||||||
FILE_FORMAT='png'
|
|
||||||
while getopts "j:i:kc:s:o:hc:f:bc" OPT; do # "j:" waits for an argument "h" doesnt
|
|
||||||
case $OPT in
|
|
||||||
h) echo "$USAGE"
|
|
||||||
exit 0 ;;
|
|
||||||
j) MAX_NPROC=$OPTARG ;;
|
|
||||||
k) CHECKFILE=1 ;;
|
|
||||||
c) CFG_FILENAME=$OPTARG ;;
|
|
||||||
o) OUTDIR=$OPTARG ;;
|
|
||||||
s) SLEEPTIME=$OPTARG ;;
|
|
||||||
b) BACKGROUND='-background transparent ';;
|
|
||||||
i) INPUT_FILENAME=$OPTARG ;;
|
|
||||||
f) FILE_FORMAT=$OPTARG ;;
|
|
||||||
*) echo "$USAGE" >&2; exit 1; # Default.
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
# Main program
|
|
||||||
echo Using $MAX_NPROC parallel threads
|
|
||||||
check_params
|
|
||||||
|
|
||||||
# Starte die Generierung
|
|
||||||
echo $INPUT_FILE
|
|
||||||
for i in `ls $INPUT_FILE| grep .svg `
|
|
||||||
do
|
|
||||||
ID=`echo "$i" | sed -e 's/;.*//g'`
|
|
||||||
PIC_NAME=`echo "$i" | sed -e 's/.svg//g'`
|
|
||||||
FILE_PATH=$INPUT_FILE/$PIC_NAME.$FILE_FORMAT
|
|
||||||
if [ -s $FILE_PATH ] && [ $CHECKFILE -eq 1 ]
|
|
||||||
then
|
|
||||||
echo $PIC_NAME exists
|
|
||||||
else
|
|
||||||
RESIZE="${width}x${height}"
|
|
||||||
SWITCHES="-density $density"'x'"$density $BACKGROUND$INPUT_FILE/$ID -resize $RESIZE $INPUT_FILE/$PIC_NAME.$format"
|
|
||||||
CMDLINE="$CMD $SWITCHES"
|
|
||||||
echo $CMDLINE
|
|
||||||
(echo $ID; $CMDLINE) &
|
|
||||||
|
|
||||||
|
|
||||||
while [ `ps -clx|grep -w 'convert' |wc -l` -ge $MAX_NPROC ]; do
|
|
||||||
sleep $SLEEPTIME
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
wait # wait for all processes to finish before exit
|
|
||||||
|
|
||||||
if [ ! -z $OUTDIR ]; then
|
|
||||||
echo -n moving to $OUTDIR
|
|
||||||
if [ ! -d $OUTDIR ]; then
|
|
||||||
echo creating directory $OUTDIR
|
|
||||||
mkdir $OUTDIR
|
|
||||||
fi
|
|
||||||
mv $PICCREATE_OUT/*.jpg $OUTDIR
|
|
||||||
echo done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# vi:set wrapmargin=0 ai showmatch ts=4 syntax=sh:
|
|
||||||
+3
-8
@@ -1,11 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
. setenv.sh
|
. setenv.sh
|
||||||
# Wo ist das Programm hinkopiert
|
|
||||||
if [ -z $PICCREATE ];then
|
|
||||||
echo please check environment
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
CMD=convert
|
|
||||||
SECTION_NAME=png
|
|
||||||
|
|
||||||
. $PICCREATE_BIN/generationlib
|
# SVG Bilder mit ImageMagick in JPG/PNG umwandeln
|
||||||
|
# svgconvert.sh -c punkteraetsel --format png -p
|
||||||
|
python3 $PICCREATE_LIBS/svgconvert.py "$@"
|
||||||
|
|||||||
+5
-5
@@ -129,8 +129,7 @@ Die Sektionen `[jpgs]`, `[png]` usw. beschreiben die Rastergrafiken für
|
|||||||
## SVG in JPG/PNG umwandeln
|
## SVG in JPG/PNG umwandeln
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd libs
|
./svgconvert.sh -c punkteraetsel --format png -p
|
||||||
python3 svgconvert.py -c punkteraetsel.cfg --format png -p
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Wandelt alle SVGs in `$PICCREATE_OUT` (oder `-s <ordner>`) parallel mit
|
Wandelt alle SVGs in `$PICCREATE_OUT` (oder `-s <ordner>`) parallel mit
|
||||||
@@ -138,13 +137,14 @@ ImageMagick um. `--format` wählt die Sektion aus der Konfiguration.
|
|||||||
|
|
||||||
| Option | Bedeutung |
|
| Option | Bedeutung |
|
||||||
|-----------------|--------------------------------------------------------|
|
|-----------------|--------------------------------------------------------|
|
||||||
| `-c` | Konfiguration (mit Endung `.cfg`) |
|
| `-c` | Konfiguration aus `cfg/` (Endung `.cfg` optional) |
|
||||||
| `--format` | Sektion/Format, z. B. `png` oder `jpgs` (Standard `jpg`) |
|
| `--format` | Sektion/Format, z. B. `png` oder `jpgs` (Standard `jpg`) |
|
||||||
| `-i` | CSV prüfen: fehlende Bilder melden, nur diese umwandeln |
|
| `-i` | CSV aus `in/` prüfen: fehlende Bilder melden, nur diese umwandeln |
|
||||||
| `-j` | Anzahl paralleler Jobs (Standard 8) |
|
| `-j` | Anzahl paralleler Jobs (Standard 8) |
|
||||||
| `-b` | Hintergrundfarbe, `none` für transparent |
|
| `-b` | Hintergrundfarbe, `none` für transparent |
|
||||||
| `-f` | vorhandene Bilder überschreiben |
|
| `-f` | vorhandene Bilder überschreiben |
|
||||||
| `-p` / `-v` | Fortschrittsbalken / ausführliche Ausgabe |
|
| `-p` / `-v` | Fortschrittsbalken / ausführliche Ausgabe |
|
||||||
|
| `-s` | Ordner mit den SVGs (Standard `$PICCREATE_OUT`) |
|
||||||
| `-y` | Probelauf ohne Umwandlung |
|
| `-y` | Probelauf ohne Umwandlung |
|
||||||
|
|
||||||
## Vorschaubilder von Webseiten (webscan)
|
## Vorschaubilder von Webseiten (webscan)
|
||||||
@@ -275,7 +275,7 @@ Beispiel:
|
|||||||
```bat
|
```bat
|
||||||
cd bin
|
cd bin
|
||||||
piccreate.bat -c punkteraetsel -i test
|
piccreate.bat -c punkteraetsel -i test
|
||||||
svgconvert.bat -c punkteraetsel.cfg --format png -p
|
svgconvert.bat -c punkteraetsel --format png -p
|
||||||
```
|
```
|
||||||
|
|
||||||
Die `.bat`-Dateien nehmen das Python aus `.venv`, falls vorhanden, sonst den
|
Die `.bat`-Dateien nehmen das Python aus `.venv`, falls vorhanden, sonst den
|
||||||
|
|||||||
+3
-2
@@ -17,6 +17,7 @@ import csv
|
|||||||
from string import Template
|
from string import Template
|
||||||
from concurrent import futures
|
from concurrent import futures
|
||||||
from progressbar import EasyProgressBar
|
from progressbar import EasyProgressBar
|
||||||
|
from utils import CompleteEnding
|
||||||
|
|
||||||
|
|
||||||
# ImageMagick 7 heisst "magick"; unter Windows ist "convert" ein Systemprogramm
|
# ImageMagick 7 heisst "magick"; unter Windows ist "convert" ein Systemprogramm
|
||||||
@@ -154,7 +155,7 @@ def main():
|
|||||||
filelist = getfilelist(work_path)
|
filelist = getfilelist(work_path)
|
||||||
#load and override the default config if we receive an config file
|
#load and override the default config if we receive an config file
|
||||||
if options.config:
|
if options.config:
|
||||||
config_path = os.path.expandvars(os.path.join('$PICCREATE_CFG', options.config))
|
config_path = os.path.expandvars(os.path.join('$PICCREATE_CFG', CompleteEnding(options.config, 'cfg')))
|
||||||
if not os.path.exists(config_path):
|
if not os.path.exists(config_path):
|
||||||
print('\"'+ config_path +'\" does not exist. Please give the name of a config file!')
|
print('\"'+ config_path +'\" does not exist. Please give the name of a config file!')
|
||||||
return None
|
return None
|
||||||
@@ -175,7 +176,7 @@ def main():
|
|||||||
pic_config['customerid'] = origin
|
pic_config['customerid'] = origin
|
||||||
#chek if all files from the csv were successfully created and in the workfolder
|
#chek if all files from the csv were successfully created and in the workfolder
|
||||||
if options.infile:
|
if options.infile:
|
||||||
csv_path = os.path.expandvars(os.path.join('$PICCREATE_IN', options.infile))
|
csv_path = os.path.expandvars(os.path.join('$PICCREATE_IN', CompleteEnding(options.infile, 'csv')))
|
||||||
if not os.path.exists(csv_path):
|
if not os.path.exists(csv_path):
|
||||||
print('\"'+ csv_path +'\" does not exist. Please give the correct name of a csv file!')
|
print('\"'+ csv_path +'\" does not exist. Please give the correct name of a csv file!')
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user