LoginSignup
1
1

More than 5 years have passed since last update.

bash + ImageMagick > rainbow colorのボックスを作る v0.1

Last updated at Posted at 2018-08-07
動作環境
CentOS release 6.9 (Final)
GNU Bash-4.1
ImageMagick Version: ImageMagick 6.7.2-7 2017-03-22 Q16

処理概要

  • 内側から外側までrainbow colorのボックスを作る
  • ImageMagickコマンドをbashスクリプトで使う

code v0.1

layered_image_180807_exec
#!/usr/bin/bash/env

set -eu # just in case

# v0.1 Aug. 07, 2018
#   - draw rainbow colored layered image

WRK1_FILE="wrk1.png"  # work file (arbitrary names)
WRK2_FILE="wrk2.png"  # work file (arbitrary names)
OUT_FILE="out.png"    # output

wrksize=100  # size of the image
incsize=10   # increment size

#------------------------------
#CONFIGURATION
#   colors from innermost to outer
COLS=("violet" "indigo" "blue" "green" "yellow" "orange" "red")
#------------------------------

#1. base image
sizestr=$(echo $wrksize | awk '{print $1"x"$1}')  # e.g. 100x100
convert -size $sizestr xc:${COLS[0]} $WRK1_FILE

#2. expand image
((maxloop=${#COLS[*]}-1))
for idx in $(seq 1 $maxloop)
do
  ((wrksize=wrksize+incsize*2))
  sizestr=$(echo $wrksize | awk '{print $1"x"$1}')  # e.g. 100x100
  echo $sizestr
  convert $WRK1_FILE -page +10+10 -background ${COLS[idx]} \
    -extent $sizestr -flatten $WRK2_FILE
  cp $WRK2_FILE $WRK1_FILE
done

#3. output 
mv $WRK2_FILE $OUT_FILE

#remove temporary files
rm -f $WRK1_FILE

echo "[$OUT_FILE] is produced"

設定

上記のCONFIGURATION記載の色名のarrayを変更すると、それに合わせて色が付く。

実行

run
$ bash layered_image_180807_exec 
120x120
140x140
160x160
180x180
200x200
220x220
[out.png] is produced

eog out.pngで見たのが以下。

qiita.png

参考

情報感謝です。

画像の用途

画像の一部を切り出して合成する時に、切り出しがうまく行ったかを確認するために上記のような画像を使う。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1