-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.sh
executable file
·109 lines (92 loc) · 4.31 KB
/
convert.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
# Das Skript konvertiert die originalen TIFFs in die diversen JPEGs, die die
# Faust-Webapp benötigt. In den nächsten Zeilen konfigurieren und dann
# ./convert.sh ausführen. Bereits konvertierte Dateien werden nicht neu
# konvertiert.
#
# Das Skript benötigt neben dem üblichen Unix-Toolchain ImageMagick.
### Konfiguration:
# Eingabeverzeichnis. Hier liegen Unterverzeichnisse mit den Original-Digitalisaten drin
#input_dir="$PWD"/img/tif
#input_dir="/media/vitt/909613EC9613D218/Drucke"
#input_dir="/run/user/1000/gvfs/afp-volume:host=NAS.local,user=tv,volume=Thorsten/backup/faust/hdd-gerrit/Drucke/print"
#input_dir="/faust/img/tif"
input_dir="/home/tv/tmp/print"
# Ausgabeverzeichnis. Darin entstehen Verzeichnise jpg, jpg_tiles und metadata
output_dir=/home/tv/tmp/facsimile
#output_dir=/faust/transcript/facsimile
### Detailanpassung, hier idR nichts verändern:
current_dir="$PWD"
output_jpg="$output_dir/jpg"
output_tiles="$output_dir/jpg_tiles"
output_metadata="$output_dir/metadata"
#zoom_levels must be larger than 0
zoom_levels="8"
tile_width="256"
tile_height="256"
################################################
# go to input dir to explore files and folders
cd "$input_dir"
find . -type d > "$current_dir/temp_input_folders.txt"
# create output folder structure. it shall mimic the input folder structure
mkdir -p "$output_jpg"
cd "$output_jpg"
xargs mkdir -p < "$current_dir/temp_input_folders.txt"
mkdir -p "$output_tiles"
cd "$output_tiles"
xargs mkdir -p < "$current_dir/temp_input_folders.txt"
mkdir -p "$output_metadata"
cd "$output_metadata"
xargs mkdir -p < "$current_dir/temp_input_folders.txt"
rm "$current_dir/temp_input_folders.txt"
# create jpg and scaled jpg
# first find all *.tga files
# then sed filenames to absolute path of input and output file
# next create a convert-command and execute it (start conversion tga->jpg)
# finally create scaled jpg
cd "$input_dir"
find . -type f -name "*.tif" -print0 | while IFS= read -r -d '' file
do
# Generating the JSON file is the last step, so we can use that as an
# indicator on whether we need to do something for this input file at all
json_file=$(echo "$file" | sed "s#^\.#"$output_metadata"#;s/\.tif$/\.json/" )
if [ -s "$json_file" ]
then
continue
fi
echo "Converting $file ..."
#convert tga->jpg and create preview images with max size 240x360 (widthXheight)
out_file1=$(echo "$file" | sed "s#^\.#"$input_dir"#" )
out_file2=$(echo "$file" | sed "s#^\.#"$output_jpg"#;s/\.tif$/_0\.jpg/" )
out_file3=$(echo "$file" | sed "s#^\.#"$output_jpg"#;s/\.tif$/_preview\.jpg/" )
cmd="convert -quiet ${out_file1}[0] -strip $out_file2"
echo "running: $cmd"
convert -quiet "${out_file1}"[0] -strip "${out_file2}"
convert -quiet "${out_file1}"[0] -strip -resize 240x360 "${out_file3}"
#scale images
echo " creating scaled images"
for i in `seq 0 $((zoom_levels-1))`
do
scaled_file1=$(echo "$out_file2" | sed "s/[0-9]\.jpg/$i\.jpg/" )
scaled_file2=$(echo "$out_file2" | sed "s/[0-9]\.jpg/$((i+1))\.jpg/" )
cmd="convert -quiet $scaled_file1 -thumbnail 50% $scaled_file2"
# echo " $cmd"
convert -quiet "${scaled_file1}" -thumbnail 50% "${scaled_file2}"
done
#create tiles
echo " creating tiles"
for i in `seq 0 ${zoom_levels}`
do
scaled_file=$(echo "$scaled_file1" | sed "s/[0-9]\.jpg/$i\.jpg/" )
tiled_file=$(echo "$scaled_file" | sed "s/\.jpg/_%\[filename:tile\]\.jpg/;s#"$output_jpg"#"$output_tiles"#" )
cmd="convert -quiet $scaled_file -strip -crop ${tile_width}x${tile_height} -set filename:tile %[fx:page.x/${tile_width}]_%[fx:page.y/${tile_height}] +repage +adjoin $tiled_file"
# echo " $cmd"
convert -quiet "${scaled_file}" -strip -crop ${tile_width}x${tile_height} -set filename:tile %[fx:page.x/${tile_width}]_%[fx:page.y/${tile_height}] +repage +adjoin "${tiled_file}"
done
#create json metadata
echo " creating json metadata"
#json_file=$(echo "$file" | sed "s#^\.#"$output_metadata"#;s/\.tif$/\.json/" )
image_width=$(identify -format '%w' "$file" 2>/dev/null)
image_height=$(identify -format '%h' "$file" 2>/dev/null)
printf "{\n \"imageWidth\": %s,\n \"imageHeight\": %s,\n \"tileWidth\": %s,\n \"tileHeight\": %s,\n \"zoomLevels\": %s\n}" ${image_width} ${image_height} ${tile_width} ${tile_height} ${zoom_levels} > "${json_file}"
done