Skip to content

Instantly share code, notes, and snippets.

@xopr

xopr/mosaicbg.sh

Last active Nov 8, 2020
Embed
What would you like to do?
Generate mosaic from testcards
#!/bin/bash
WIDTH=1280
HEIGHT=720
if [ $# -eq 0 ]; then
echo "Testcard mosaic generator: generate 1 to 9 mosaic labeled testscreens"
echo -e "\tUses read, sed, wget and ImageMagick (convert and montage)"
echo -e "\tIt also uses Terence Eden's Testcard <https://github.com/edent/SVGtestcard>"
echo -e "\tUsage: $0 <name>[,subtitle>] [name[,subtitle]..]"
exit 1
fi
read --help 2>&1 > /dev/null
if [ $? -ne 2 ]; then
echo "cannot find 'read'"
exit 2
fi
if ! which sed 2>&1 > /dev/null; then
echo "cannot find 'sed'"
exit 3
fi
if ! which convert 2>&1 > /dev/null; then
echo "cannot find 'convert' (install ImageMagick)"
exit 4
fi
if ! which montage 2>&1 > /dev/null; then
echo "cannot find 'montage' (install ImageMagick)"
exit 4
fi
if [ ! -f "PM5644.svg" ]; then
if ! which wget 2>&1 > /dev/null
then
echo "cannot find 'wget'"
exit 5
fi
wget "https://raw.githubusercontent.com/edent/SVGtestcard/master/PM5644.svg"
fi
#TODO: placeholder.svg/png
if [ ! -f "bg.png" ]; then
echo "Generating placeholder.."
convert -size ${WIDTH}x${HEIGHT} plasma:fractal bg.png
fi
echo -n "Generating $# tile(s).."
TILES=0
while [[ $# -gt 0 ]]
do
IFS=',' read -ra TEXT <<< "$1"
echo -n "$TILES.."
if [ -z "${TEXT[1]}" ]
then
cat PM5644.svg|sed -e"s/width=\"[^\"]*\" height=\"[^\"]*\" viewBox/width=\"${WIDTH}px\" height=\"${HEIGHT}px\" viewBox/g" -|sed -e"s/LDO TV/${TEXT[0]}/g" -|convert -size ${WIDTH}x${HEIGHT} - CH${TILES}.png
else
cat PM5644.svg|sed -e"s/width=\"[^\"]*\" height=\"[^\"]*\" viewBox/width=\"${WIDTH}px\" height=\"${HEIGHT}px\" viewBox/g" -|sed -e"s/LDO TV/${TEXT[0]}/g" -|sed -e"s/\(<\!--\|-->\)//g" -|sed -e"s/DIGITAL/${TEXT[1]}/g" -|convert -size ${WIDTH}x${HEIGHT} - CH${TILES}.png
fi
shift
let TILES+=1
done
echo "done"
#-background '#336699'
echo "Tile montage.."
case $TILES in
1) mv CH0.png mosaicbg.png;;
2) montage bg.png CH0.png CH1.png bg.png -tile 2x2 -geometry +0+0 -resize 50% mosaicbg.png;;
3) montage bg.png CH0.png CH1.png CH2.png -tile 2x2 -geometry +0+0 -resize 50% mosaicbg.png;;
4) montage CH0.png CH1.png CH2.png CH3.png -tile 2x2 -geometry +0+0 -resize 50% mosaicbg.png;;
5) montage CH0.png bg.png CH1.png bg.png CH2.png bg.png CH3.png bg.png CH4.png -tile 3x3 -geometry +0+0 -resize 33.33% mosaicbg.png;;
6) montage CH0.png CH1.png CH2.png bg.png bg.png bg.png CH3.png CH4.png CH5.png -tile 3x3 -geometry +0+0 -resize 33.33% mosaicbg.png;;
7) montage CH0.png CH1.png CH2.png bg.png CH3.png bg.png CH4.png CH5.png CH6.png -tile 3x3 -geometry +0+0 -resize 33.33% mosaicbg.png;;
8) montage CH0.png CH1.png CH2.png CH3.png bg.png CH4.png CH5.png CH6.png CH7.png -tile 3x3 -geometry +0+0 -resize 33.33% mosaicbg.png;;
9) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png CH6.png CH7.png CH8.png -tile 3x3 -geometry +0+0 -resize 33.33% mosaicbg.png;;
10) montage CH0.png CH1.png CH2.png CH3.png CH4.png bg.png bg.png bg.png bg.png bg.png bg.png CH5.png CH6.png CH7.png CH8.png CH9.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
11) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png bg.png bg.png bg.png bg.png bg.png CH6.png CH7.png CH8.png CH9.png CH10.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
12) montage CH0.png CH1.png CH2.png CH3.png CH4.png bg.png bg.png CH5.png CH6.png bg.png bg.png CH7.png CH8.png CH9.png CH10.png CH11.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
13) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png bg.png CH6.png CH7.png bg.png bg.png CH8.png CH9.png CH10.png CH11.png CH12.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
14) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png bg.png CH6.png CH7.png bg.png CH8.png CH9.png CH10.png CH11.png CH12.png CH13.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
15) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png CH6.png CH7.png bg.png CH8.png CH9.png CH10.png CH11.png CH12.png CH13.png CH14.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
16) montage CH0.png CH1.png CH2.png CH3.png CH4.png CH5.png CH6.png CH7.png CH8.png CH9.png CH10.png CH11.png CH12.png CH13.png CH14.png CH15.png -tile 4x4 -geometry +0+0 -resize 25% mosaicbg.png;;
*)
echo "Too much tiles"
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.