I am creating a Rails app which is hosted on Heroku and that allows the user to generate animated GIFs on the fly based on an original JPG that's hosted somewhere in the web (think of it as a crop-resize app). I tried Paperclip but, AFAIK, it does not handle dynamically-generated files. I am using the `aws-sdk` gem and this is a code snippet of my controller:

```
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

```

That is for the basic creation of a two-frame animation. RMagick can generate a GIF in my development computer with these lines:

```
list.write("#{Rails.public_path}/images/" + @animation.filename)

```

I tried uploading the `list` structure to 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)

```

But I don't have a `size` method in `RMagick::ImageList` that I can use to specify that. I tried "precompiling" the GIF into another `RMagick::Image`:

```
anim = Magick::Image.new(@animation.width, @animation.height)
anim.format = "GIF"
list.write(anim)

```

But Rails crashes with a segmentation fault:

```
/path/to/my_controller.rb:103: [BUG] Segmentation fault ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
Abort trap: 6

```

Line 103 corresponds to `list.write(anim)`.

So right now I have no idea how to do this and would appreciate any help I receive.