Skip to content

Instantly share code, notes, and snippets.

@mattintosh4
Last active October 21, 2017 18:31
Show Gist options
  • Select an option

  • Save mattintosh4/7cfcf0b98a5b19d42b3a2c2d4a1e6c2f to your computer and use it in GitHub Desktop.

Select an option

Save mattintosh4/7cfcf0b98a5b19d42b3a2c2d4a1e6c2f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
set -u
set -x
## USAGE
# $ cd azur_lane
# $ ./gistfile1.sh
## DIRECTORY
# azur_lane/
# |-- gistfile1.sh
# |-- 駆逐
# | |-- 000.png
# | `-- 001.png
# |-- 軽巡
# |-- 重巡
# |-- 戦艦
# `-- 空母
# 画像の横幅(デフォルト:480px)
card_width=${card_width:-480}
# 画像の列数(デフォルト:8)
card_columns=${card_columns:-8}
# ナンバリング用フォント
font1_family="Stencil-Cargo-Army"
font1_color="#1118"
font1_size="96"
font1_offset="+8+48"
# タイトル用フォント
font2_family="Stencil-WW-II"
font2_color="#eee8"
font2_size="128"
font2_offset="+0+8"
background="-define gradient:angle=160 gradient:#169-#111"
gen(){( srcroot=${1:?} title=${2:?} output=${3:?}
test -d "${srcroot}"
tmpdir=`mktemp -d`/
test "${tmpdir}" != "/"
(
cd "${srcroot}"
for f in *.png
do
test -f "${f}" || continue
convert \
\( \
"${f}" \
-gravity NorthWest \
-font "${font1_family}" \
-pointsize "${font1_size}" \
-fill "${font1_color}" \
-annotate "${font1_offset}" "${f%.*}" \
-filter Lanczos2Sharp -resize ${card_width}x \
\) \
\( +clone -background black -shadow 40x2 \) +swap \
+repage -gravity Center -composite \
${tmpdir}"${f%.*}"_tmp.png \
& sleep 0.1
done
wait
)
montage ${tmpdir}*.png \
-tile ${card_columns}x \
-geometry +4+4 \
-background none \
miff:- \
| convert fd:0 \
-gravity North -background none -splice x128 \
-gravity NorthWest \
-font "${font2_family}" \
-fill "${font2_color}" \
-pointsize "${font2_size}" \
-annotate "${font2_offset}" "${title}" \
"${output}"
rm -r "${tmpdir}"
)}
combine(){( : ${1:?} # File names
combine_func(){( : ${1:?} # File names
montage "${@}" \
-tile 1 \
-geometry +4+4 \
-background none \
miff:- \
| convert fd:0 \
-trim \
-bordercolor none \
-border 32 \
miff:-
)}
eval `combine_func "${@}" | identify -format "w=%w h=%h" fd:0`
combine_func "${@}" \
| convert \
\( \
\( -size ${w}x${h} ${background} \) \
\( -size 32x32 xc: +noise random -virtual-pixel tile -blur 0x4 -level +40% -resize ${w}x${h}\! \) \
-compose Modulate \
-composite \
\) \
fd:0 \
-compose Over \
-composite 9999.png
)}
convert -list font | grep -isq "${font1_family}"
convert -list font | grep -isq "${font2_family}"
gen 駆逐 "DESTROYER" 0001.png &
gen 軽巡 "LIGHT CRUISER" 0002.png &
gen 重巡 "HEAVY CRUISER" 0003.png &
gen 戦艦 "BATTLESHIP" 0004.png &
gen 空母 "CARRIER" 0005.png &
wait
combine 0001.png 0002.png 0003.png 0004.png 0005.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment