Skip to content

Instantly share code, notes, and snippets.

@Wikinaut
Last active April 30, 2024 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wikinaut/692a9b769f42defed810e7b8fa6797ea to your computer and use it in GitHub Desktop.
Save Wikinaut/692a9b769f42defed810e7b8fa6797ea to your computer and use it in GitHub Desktop.
Make nxm
#! /bin/bash
# LINUX convert \( aa.png aa.png aa.png aa.png aa.png +append \) \( aa.png aa.png aa.png aa.png aa.png +append \) -append -gaussian-blur 0.5x0.5 x.png
# call make-nxm <image-filename> rows columms [postfilter-command]
POSTFILTER="-gaussian-blur 0.5x0.5"
MARGIN=20
if [ $# -lt 3 ] ; then
echo
echo "Create a composed n x m image from a single image"
echo
echo "Usage: make-nxm image-filename rows colums [innermargin] [postfilter-command]"
echo " default gap between immages: ${MARGIN}"
echo " default postfilter: ${POSTFILTER}"
echo
echo "Examples: make-nxm img.png 2 4"
echo " make-nxm img.png 2 4 ${MARGIN}"
echo " make-nxm img.png 2 4 ${MARGIN} ${POSTFILTER}"
echo
echo " create output image 2x4_img.png"
echo " composed of 2 rows and 4 columns of img.png"
echo " with a gap of ${MARGIN} pixels between the images"
echo " with gaussian blur filter 0.5x0.5 (default filter)"
echo
exit
fi
if [[ $4 == ?(-)+([[:digit:]]) ]] ; then
MARGIN=$4
if [ $# -gt 4 ] ; then
POSTFILTER="$5 $6 $7 $8 $9"
fi
else
if [ $# -gt 3 ] ; then
POSTFILTER="$4 $5 $6 $7 $8"
fi
fi
FILENAME=$1
ROWS=$2
COLUMNS=$3
OUTFILENAME=${COLUMNS}x${ROWS}_${FILENAME}
echo "${ROWS} rows and ${COLUMNS} columns"
echo "margin (gap) between images: ${MARGIN}px"
echo "Postfilter: ${POSTFILTER}"
# default
# INNERMARGIN="+append"
INNERMARGIN="-background white -splice ${MARGIN}x${MARGIN}+0+0 +append -chop ${MARGIN}x0+0+0"
y=""
row=1; while [ $row -le $ROWS ]; do y="$y $FILENAME "; row=$[$row+1]; done
col=1; while [ $col -le $COLUMNS ]; do z="$z ( $y $INNERMARGIN ) "; col=$[$col+1]; done
convert $z -append -chop 0x${MARGIN}+0+0 $POSTFILTER ${OUTFILENAME}
convert ${OUTFILENAME} -resize 3000 ${OUTFILENAME%.*}_reduced.${OUTFILENAME##*.}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment