gpt4 book ai didi

ruby - RMagick 无法打开图像

转载 作者:太空宇宙 更新时间:2023-11-03 18:22:24 25 4
gpt4 key购买 nike

今天我试着写一个代码从文件夹生成动画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

非常感谢;)

最佳答案

ImageList.new 需要文件名作为参数,一次一个。您只提供一个参数,即串联文件名的字符串。所以不是

f = files.join(',').to_s
animation = ImageList.new("#{f}")

使用

animation = ImageList.new *files

*files 指示 ruby​​ 将数组成员扩展为单独的参数

关于ruby - RMagick 无法打开图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16108723/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com