ImageMagick绘制了一系列具有不断增长的发光效果的图像

时间:2013-07-03 19:10:28

标签: imagemagick

我正在学习ImageMagick。我想创建(使用ImageMagick)一系列图像 使用命令后

convert -delay 0 -loop 0 frame*.gif final.gif

给出结果,如附加的动画gif。

enter image description here

我想自己编写一系列命令,但我需要提示哪些效果和绘图说明会给我最相似的结果,所以我正在寻找类似的东西:

  • 画一个圆圈
  • 模糊
  • 保存框架
  • 增加圆的半径
  • 重复

但是,上述可能还不够。

这个问题是否很模糊,或者有人可以给我一个提示?

1 个答案:

答案 0 :(得分:7)

如果您处于shell环境(OSX或Linux)中,您可以执行类似这样的操作,这会在不断增加的半径中创建一系列模糊的圆圈,并将图像保存在适当命名的文件中...

for RAD in {10,20,30,40,50,60,70,80,90}; do convert -size 400x300 xc:black -fill cyan -stroke cyan -draw "translate 200,150 circle 0,0 $RAD,0" -blur 0x8 blur_circle$RAD.gif; done

为了获得更好的效果,您可以添加重复的模糊操作,或者为更大的半径添加更多模糊。

然后,正如你建议将它们转换为动画gif:

convert -delay 0 -loop 0  blur_circle*.gif final.gif

编辑

工作版更接近原始“愿景”

这是一个使用python生成两个圆的版本,其透明度在不同的时间尺度上有所不同。使用当前设置,随着时间的推移透明度如下图所示,但您可以生成任何整数值列表以获得不同的效果:

alpha-time graph

这是该程序产生的图像:

glowingcircles

这是程序本身:

#! /usr/bin/env python
""" Using imagemagick, generate a series of .gifs with fuzzy circles in them... 

When the program is done, create an animated gif with:
    convert -delay 0 -loop 0  blur_circle*.gif final.gif

(P.S. I know it is not 'convention' to capitalize variable names, but it makes
it easier to distinguish my definitions from built-ins)"""

import subprocess
import sys

CanvasW = 400
CanvasH = 400
CenterX = int(CanvasW/2)
CenterY = int(CanvasH/2)
InnerDia = 75
OuterDia = 155

BaseNameString = "blur_circles"

# play with overall blur level - 2 to 8
# this is in addition to the distance fuzzing
BlurLevel = '8'

# The following three lists must be the same length
# Transparency levels of the inner circle, ramping up and down 
InnerAlphaList = range(0,101,10)  + range(90,9,-20) + [5,0,0,0]
print "Inner:",len(InnerAlphaList),InnerAlphaList

# Transparency of the outer circle
OuterAlphaList = range(0,51,8) +  range(40,9,-12) + range(8,0,-2) + [0,0,0,0,0,0]
print "Outer:",len(OuterAlphaList), OuterAlphaList

# Add 100 so the file names get sorted properly?
NameNumberList = range(101, 101+len(InnerAlphaList))

# Changing the Euclidaan distance parameters affects how fuzzy the objects are

BaseCommand = '''convert -size {w}x{h} xc:black \
  -fill  "rgba( 0, 255,255 , {outal:0.1f} )" -stroke  none -draw "translate {cenx},{ceny} circle 0,0 {outdia},0" -morphology Distance Euclidean:4,1000\
  -fill  "rgba( 0, 255,255 , {inal:0.1f} )"  -stroke  none -draw "translate {cenx},{ceny} circle 0,0 {india},0"  -morphology Distance Euclidean:4,500 \
  -blur 0x{blur} {basename}_{namenum}.gif'''

sys.stderr.write("Starting imagegen .")
for InAlpha,OutAlpha,NameNumber in  zip(InnerAlphaList,OuterAlphaList,NameNumberList):
    FormattedCommand = BaseCommand.format(
        w = CanvasW, h = CanvasH,
        cenx = CenterX, ceny = CenterY,
        india = InnerDia, outdia = OuterDia,
        blur = BlurLevel,
        inal = InAlpha/100.0, outal = OutAlpha/100.0,
        basename = BaseNameString,
        namenum = NameNumber
    )
    sys.stderr.write(".")
    # sys.stderr.write("{}\n".format(FormattedCommand))

    ProcString = subprocess.check_output(FormattedCommand, stderr=subprocess.STDOUT,shell=True) 
    if ProcString:
        sys.stderr.write(ProcString)
sys.stderr.write(" Done.\n")




""" BASE COMMANDS:
 # inner circle:
 convert -size 400x300 xc:black -fill  "rgba( 0, 255,255 , 1 )" -stroke  none -draw "translate 200,150 circle 0,0 75,0" -blur 0x8 -morphology Distance Euclidean:4,1000  blur_circle100.gif

 #outer circle
 convert -size 400x300 xc:black -fill  "rgba( 0, 255,255 , .5 )" -stroke  none -draw "translate 200,150 circle 0,0 150,0"  -morphology Distance Euclidean:4,500  -blur 0x6 blur_circle100.gif

 #both circles
 convert -size 400x300 xc:black -fill  "rgba( 0, 255,255 , .5 )" -stroke  none -draw "translate 200,150 circle 0,0 150,0"  -morphology Distance Euclidean:4,500 \
  -fill  "rgba( 0, 255,255 , 1 )" -stroke  none -draw "translate 200,150 circle 0,0 75,0" -morphology Distance Euclidean:4,1000\
  -blur 0x8 blur_circle100.gif
"""