如何制作如下图链接中的图片。服务器上每5分钟运行一次脚本,检查服务器是启动还是关闭。我的文件具有日期时间戳,状态为1/0,用于向上和向下。现在我需要制作与图像相同的图形。
状态文件如下所示:
Wed Mar 4 13:18:42 UTC 2015, Serverup
Wed Mar 4 13:23:42 UTC 2015, Serverup
Wed Mar 4 13:28:42 UTC 2015, Serverdown
Wed Mar 4 13:33:42 UTC 2015, Serverup
Wed Mar 4 13:38:42 UTC 2015, Serverup
Wed Mar 4 13:43:42 UTC 2015, Serverup
答案 0 :(得分:1)
每次使用ImageMagick确定其UP / DOWN状态时,我都会在服务器上重新生成图像。它安装在大多数Linux发行版上,可用于OSX和Windows。
这是制作图像的小脚本,然后您只需在HTML中选取该图像。它评论很好,所以你可以看到它在做什么:
#!/bin/bash
blockw=8 # width of up/down block
blockh=20 # height of up/down block
datew=100 # width of field containing date
dateh=60 # height of field containing date
xpos=0 # current output position
# Generate key to colours (BLUE part of explanatory image)
convert -background none -gravity west -pointsize 36 \
-size 60x60 xc:green \
-size 300x60 label:"Server UP" \
-size 60x60 xc:red \
-size 300x60 label:"Server DOWN" +append key.png
# Parse server status file
while read junk day date rest; do
day="$day $date"
# Set colour, green for up, and overwrite with red if down
colour="green"
[[ $rest == *"own"* ]] && colour="red"
# Just output our standard red/green status block (YELLOW part of explanatory image)
convert -size ${blockw}x${blockh} xc:$colour miff:-
# If day has changed, remember day for next time, and output it too
if [ "$day" != "$prevday" ]; then
prevday=$day
# Create our label for today
convert -size ${datew}x${dateh} -background none -pointsize 36 label:"$day" today.png
if [ $xpos -eq 0 ]; then
# Create very first datebar file
mv today.png datebar.png
datex=$datew
else
# Second or subsequent date, append to datebar file at correct position (MAGENTA part of explanatory image)
((xpad=xpos-datex))
convert -background none datebar.png -size ${xpad}x${dateh} xc:none today.png +append datebar.png
# Keep track of width of datebar
((datex=datex+xpad+datew))
fi
fi
# Keep track of our x position
((xpos+=blockw))
done < status.csv | convert -background white - +append \
datebar.png -append \
-gravity center -extent 110x600% \
-gravity South key.png -composite result.png
这是它的作用:
只是为了解释,如果你不熟悉ImageMagick,图像由3部分组成,在下图中以蓝色,黄色和洋红色着色。我已经标记了代码以显示每个地方正在生成哪个部分。