From ecd776996556682faea10567ca011f4a147d3ea3 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sat, 24 Jun 2017 22:23:55 +0200 Subject: Initial commit --- combine-images | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 combine-images diff --git a/combine-images b/combine-images new file mode 100755 index 0000000..e1b6e8c --- /dev/null +++ b/combine-images @@ -0,0 +1,89 @@ +#!/bin/bash + +set -e + +tmp_dir="$(mktemp -d)" +trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT + +if [ $# -ne 3 ]; then + echo 'Verwendung: combine-images Geometrie Dateistamm_ Endung' + echo ' Geometrie hat die Form "Breite"x"Hoehe"+"x-Offset"+"y-Offset"' + exit 1 +fi + +geometry="$1" +stem="$2" +ending="$3" + +files="$( + ls "$(dirname "${stem}")" | \ + grep "^$(basename "${stem}")[0-9]\+_[0-9]\+\.${ending}\$" +)" + +numbers="$( + echo "${files}" | \ + sed " + s|^$(basename "${stem}")|| + s|\.${ending}\$|| + " | \ + sort +)" + +min_x="$( + echo "${numbers}" | \ + sed 's|_[0-9]\+$||' | \ + sort -nr | \ + tail -n1 +)" + +max_x="$( + echo "${numbers}" | \ + sed 's|_[0-9]\+$||' | \ + sort -n | \ + tail -n1 +)" + +min_y="$( + echo "${numbers}" | \ + sed 's|^[0-9]\+_||' | \ + sort -nr | \ + tail -n1 +)" + +max_y="$( + echo "${numbers}" | \ + sed 's|^[0-9]\+_||' | \ + sort -n | \ + tail -n1 +)" + +if ! [ "${numbers}" = "$( + for ((x=${min_x}; x<=${max_x}; x++)); do + for ((y=${min_y}; y<=${max_y}; y++)); do + echo "${x}_${y}" + done + done + )" ]; then + echo 'Die angegebenen Bilder ergeben kein Rechteck!' + exit 1 +fi + +for ((x=${min_x}; x<=${max_x}; x++)); do + for ((y=${min_y}; y<=${max_y}; y++)); do + convert "${stem}${x}_${y}.${ending}" -crop "${geometry}" "${tmp_dir}/C${x}_${y}.bmp" + printf '.' + done + convert $( + for ((y=${max_y}; y>=${min_y}; y--)); do + printf '%s ' "${tmp_dir}/C${x}_${y}.bmp" + done + ) -append "${tmp_dir}/C${x}.bmp" + printf '.' +done + +convert $( + for ((x=${min_x}; x<=${max_x}; x++)); do + printf '%s ' "${tmp_dir}/C${x}.bmp" + done +) +append "${stem%_}.${ending}" +printf '.\n' -- cgit v1.2.3-70-g09d2