7

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

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

给出的结果就像附加的动画 gif 一样。

在此处输入图像描述

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

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

但是,可能以上还不够。

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

4

1 回答 1

8

如果您在 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生成两个圆的版本,其透明度在不同的时间尺度上有所不同。使用当前设置,随着时间的推移透明度看起来像这个图,但您可以生成任何整数值列表以获得不同的效果:

阿尔法时间图

这是程序生成的图像:

发光的圆圈

这是程序本身:

#! /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
"""
于 2013-08-28T00:55:49.323 回答