今天我尝试编写一个代码,用于从文件夹生成动画gif 但我得到这个错误:
.../.gem/ruby/2.0.0/gems/rmagick-2.13.2/lib/RMagick.rb:1635:in `read': unable to open image `0.jpg,3.jpg,1.jpg,2.jpg': No such file or directory @ error/blob.c/OpenBlob/2641 (Magick::ImageMagickError)
from .../.gem/ruby/2.0.0/gems/rmagick-2.13.2/lib/RMagick.rb:1635:in `block in initialize'
.../.gem/ruby/2.0.0/gems/rmagick-2.13.2/lib/RMagick.rb:1634:in `each'
.../.gem/ruby/2.0.0/gems/rmagick-2.13.2/lib/RMagick.rb:1634:in `initialize'
from .../bin/scripts/animate.rb:20:in `new'
from .../bin/scripts/animate.rb:20:in `<main>'
这是代码:
#!/usr/bin/env ruby
require 'RMagick'
include Magick
files = Dir.glob"*.jpg"
if (!ARGV[0])
puts "Usage:"
puts "animate.rb 10"
puts "-0 delay ex. 10"
else
f = files.join(',').to_s
animation = ImageList.new("#{f}")
animation.delay = ARGV[0].to_i
animation.write("animated.gif")
exit
end
非常感谢;)
答案 0 :(得分:3)
ImageList.new期望文件名作为参数,一次一个。您只提供一个参数,串联文件名字符串。而不是
f = files.join(',').to_s
animation = ImageList.new("#{f}")
使用
animation = ImageList.new *files
*files
指示ruby将数组成员扩展为单独的参数