-
Notifications
You must be signed in to change notification settings - Fork 1
/
ResizeByInk.sh
executable file
·62 lines (41 loc) · 2.75 KB
/
ResizeByInk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/sh
#Author: Johannes Kalliauer
#last Changes: (by Johannes Kalliauer)
#2017-10-29 11h06 defined inkscape alias (Johannes Kalliauer)
echo
#needed if in the bashrc ist defined: export alias inkscape='/cygdrive/c/Program\ Files/Inkscape/inkscape.com'
if [ -z ${inkscape+x} ]; then
echo not def
else
echo $inkscape
alias inkscape=$inkscape
fi
#Input parameters:
valid=1
count=0
#echo "This script allows you to convert all files in this folder from one file type to another."
for fileSource in *.svg
do
if [ -f "$fileSource" ]; then
count=$((count+1))
file=$(echo $fileSource | cut -d'.' -f1)
echo $count". "$fileSource" -> "${file}r.$outputType
chmod u+r ./${fileSource}
cp ./${fileSource} ./${file}r.svg
mv ./${fileSource} ./${file}.xml
sed -ri "s/inkscape:version=\"0.(4[\. r[:digit:]]+|91 r13725)\"//g" ./${file}r.svg # https://bugs.launchpad.net/inkscape/+bug/1763190
#inkscape --with-gui ./${file}r.svg --verb=DialogDocumentProperties --verb=FitCanvasToDrawing --export-plain-svg=${file}rR.svg --verb=FileSave --verb=FileClose --verb=FileQuit
inkscape --with-gui ./${file}r.svg --actions='DialogDocumentProperties;fit-canvas-to-selection;FitCanvasToDrawing;FileSave;FileClose;FileQuit' --batch-process
scour -i ./${file}r.svg -o ./${file}rs.svg --disable-style-to-xml --keep-unreferenced-defs --indent=space --nindent=1 --keep-editor-data
#remove useless metadata
sed -i -e ':a' -e 'N' -e '$!ba' -e "s/<metadata id=\"metadata[[:digit:]]*\">[[:space:]\r\n]*<rdf:RDF>[[:space:]\r\n]*<cc:Work rdf:about=\"\">[[:space:]\r\n]*<dc:format>image\/svg+xml<\/dc:format>[[:space:]\r\n]*<dc:type rdf:resource=\"http:\/\/purl.org\/dc\/dcmitype\/StillImage\"\/>[[:space:]\r\n]*<dc:title\/>[[:space:]\r\n]*<\/cc:Work>[[:space:]\r\n]*<\/rdf:RDF>[[:space:]\r\n]*<\/metadata>//" ${file}rs.svg
# see validBySed.sh
sed -ri "s/<sodipodi:namedview( id=\"namedview[[:digit:]]*\"|) bordercolor=\"#666666\" borderopacity=\"1(.0|)\"( gridtolerance=\"10\" guidetolerance=\"10\"|) inkscape:current-layer=\"[[:digit:]svgEbene_]*\" inkscape:cx=\"[-[:digit:].]*\" inkscape:cy=\"[-[:digit:].]*\"( inkscape:pagecheckerboard=\"0\"|) inkscape:pageopacity=\"0(.0|)\" inkscape:pageshadow=\"2\" inkscape:window-height=\"(480|[0179]*)\" inkscape:window-maximized=\"(0|1)\" inkscape:window-width=\"(640|[01259]*)\" inkscape:window-x=\"(0|[-268]*)\" inkscape:window-y=\"(0|[-238]*)\" inkscape:zoom=\"[[:digit:].]*\"( objecttolerance=\"10\"|) pagecolor=\"#ffffff\"( showgrid=\"false\"|)\/>//" ${file}rs.svg
sed -i "s/ inkscape:version=\"1.1 (c68e22c387, 2021-05-23)\"//" ${file}rs.svg
sed -i "s/ sodipodi:docname=\"[[:alnum:]_,.]*\"//" ${file}rs.svg
mv ./${file}r.svg ./${file}r.xml
else
echo "no file $fileSource found!"
fi
done
echo "$count file(s) converted!"