LoginSignup
0
1

More than 5 years have passed since last update.

ImageMagick | bash > white, blue, yellow, redの色を持つ4つのファイルを作成する > 同じサイズ | 異なるサイズ | 異なるサイズ+背景:透明

Last updated at Posted at 2017-10-03
動作環境
Xeon E5-2620 v4 (8コア) x 2
32GB RAM
CentOS 6.8 (64bit)
openmpi-1.8.x86_64 とその-devel
mpich.x86_64 3.1-5.el6とその-devel
gcc version 4.4.7 (とgfortran)
NCAR Command Language Version 6.3.0
WRF v3.7.1を使用。
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) 
Python 3.6.0 on virtualenv
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)

bashとImageMagick にて指定の色のファイルを作る。

参考

answered Jun 9 '11 at 9:18
crnv

convert -size 32x32 xc:white empty.jpg

code > 同じサイズ

上記をもとに以下を実装した。

test_make_emptyPng_171003_exec
#!/usr/bin/env bash

IMGSIZE="100x100"

for acolor in white blue yellow red;do
  convert -size $IMGSIZE xc:$acolor $acolor.png
done

実行すると以下のファイルが生成され、それぞれの色が付いた画像となる。

  • white.png
  • blue.png
  • yellow.png
  • red.png

code > 異なるサイズ

色がついた部分を異なるサイズにして、画像サイズは同じとする実装。

test_png_diffSizes_171103_exec
#!/usr/bin/env bash

EXTSIZE="100x100"

colors[0]="gray"
colors[1]="blue"
colors[2]="yellow"
colors[3]="red"

sizes[0]="40x40"
sizes[1]="60x60"
sizes[2]="80x80"
sizes[3]="100x100"

for idx in $(seq 0 3);do
    acolor=${colors[idx]}
    convert -size ${sizes[idx]} -extent $EXTSIZE xc:$acolor $acolor.png
done

code > 異なるサイズ + 背景色:透明

test_png_diffSizes_transparent_171103_exec
#!/usr/bin/env bash

EXTSIZE="100x100"

colors[0]="gray"
colors[1]="blue"
colors[2]="yellow"
colors[3]="red"

sizes[0]="40x40"
sizes[1]="60x60"
sizes[2]="80x80"
sizes[3]="100x100"

WRK_FILE="wrk.png"

for idx in $(seq 0 3);do
    acolor=${colors[idx]}
    convert -size ${sizes[idx]} xc:$acolor -extent $EXTSIZE wrk.png
    convert wrk.png -transparent "rgb(255,255,255)" $acolor.png
done

rm -f $WRK_FILE

0
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
0
1