Skip to content

Instantly share code, notes, and snippets.

@yoya
Last active January 6, 2024 15:37
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 yoya/61d8c7b37cf9306f76e7d31d1292e459 to your computer and use it in GitHub Desktop.
Save yoya/61d8c7b37cf9306f76e7d31d1292e459 to your computer and use it in GitHub Desktop.
checkboard maker powered by ImageMagick
#! /bin/bash
set -euo pipefail
# ImageMagick7 を使う時は convert を magick に書き換えた方が良いです。
IM_CONVERT=convert
if [ $# -ne 7 ];then
echo "Usage: im_checkboard.sh <width> <height> <unitx> <unity> <color1> <color2> <outputfile>"
echo "ex) im_checkboard.sh 100 100 50 70 red green output.png
exit 1
fi
width=$1 ; height=$2 ; unitx=$3 ; unity=$4 ;
color1=$5 ; color2=$6 ;
outputfile=$7
ux=`expr $unitx \* 100`
uy=`expr $unity \* 100`
# pattern:checkerboard のマス目サイズは 15x15 を 2x2 の組にした 30x30
# 16x16 を作って右下 2x2 で最小単位のマス目を作る事にする
$IM_CONVERT -size 16x16 pattern:checkerboard \
-gravity southeast -crop 2x2+0+0\! \
-auto-level -colorspace sRGB \
-fill $color1 -opaque white -fill $color2 -opaque black \
-sample ${ux}x${uy}% -write mpr:CELL \
-size ${width}x${height} tile:mpr:CELL -delete 0 \
$outputfile
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment