【发布时间】:2012-01-11 01:56:51
【问题描述】:
我正在创建一个托管在 Heroku 上的 Rails 应用程序,它允许用户根据托管在网络某处的原始 JPG 动态生成动画 GIF(将其视为裁剪调整大小的应用程序)。我试过回形针,但是,AFAIK,它不处理动态生成的文件。我正在使用aws-sdk gem,这是我的控制器的代码 sn-p:
im = Magick::Image.read(@animation.url).first
fr1 = im.crop(@animation.x1,@animation.y1,@animation.width,@animation.height,true)
str1 = fr1.to_blob
fr2 = im.crop(@animation.x2,@animation.y2,@animation.width,@animation.height,true)
str2 = fr2.to_blob
list = Magick::ImageList.new
list.from_blob(str1)
list.from_blob(str2)
list.delay = @animation.delay
list.iterations = 0
这是两帧动画的基本创建。 RMagick 可以使用以下代码在我的开发计算机中生成 GIF:
list.write("#{Rails.public_path}/images/" + @animation.filename)
我尝试将list 结构上传到 S3:
# upload to Amazon S3
s3 = AWS::S3.new
bucket = s3.buckets['mybucket']
obj = bucket.objects[@animation.filename]
obj.write(:single_request => true, :content_type => 'image/gif', :data => list)
但我在 RMagick::ImageList 中没有可用于指定的 size 方法。我尝试将 GIF “预编译”为另一个 RMagick::Image:
anim = Magick::Image.new(@animation.width, @animation.height)
anim.format = "GIF"
list.write(anim)
但 Rails 因分段错误而崩溃:
/path/to/my_controller.rb:103: [BUG] Segmentation fault ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Abort trap: 6
第 103 行对应于list.write(anim)。
所以现在我不知道该怎么做,如果我得到任何帮助,我将不胜感激。
【问题讨论】:
-
我会关注输出图像时出现的段错误,我想不出明显的原因会发生这种情况。你能从控制台运行你的代码,看看会发生什么吗?
-
谢谢。我在 rails 控制台中添加了 segfault 输出(实际上是
rails server控制台而不是rails console控制台)。 -
上面代码中的#103是哪一行?是写语句吗?
标签: ruby-on-rails image-processing heroku amazon-s3 image-uploading