# Does animated gif will work properly using RMagick?

**URL:** <https://www.ruby-forum.com/t/does-animated-gif-will-work-properly-using-rmagick/154833>\
**Category:** Rails\
**Created:** [December 4, 2008, 9:56am UTC](https://www.ruby-forum.com/t/does-animated-gif-will-work-properly-using-rmagick/154833 "2008-12-04T09:56:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 4, 2008, 9:56am UTC](https://www.ruby-forum.com/t/does-animated-gif-will-work-properly-using-rmagick/154833/1 "2008-12-04T09:56:09Z")

</div>

Dear all,

I have used RMagic to read and write a image while uploading. An  
animated gif was read from my local machine and was written in my images  
folder using RMagick. But the animated gif which i read was witten in my  
folder without animation. What should i do to write the gif image with  
animation.

Here is my code to read and write image while uploading.

image = params[:image][:blob]  
image1=params[:image][:blob].original\_filename  
imgs = Magick::Image.from\_blob(image.read)  
img = imgs.first  
File.open(RAILS\_ROOT + “/public/images/banner/” + image1 , “wb”) do |f|  
f.write(img.to\_blob)  
end

could anyone suggest me to solve this issue

Thanks in advance,

Regards,  
Jose Martin

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 4, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/does-animated-gif-will-work-properly-using-rmagick/154833/2 "2008-12-04T14:47:33Z")

</div>

On Dec 4, 2008, at 3:56 AM, dare ruby wrote:

> Here is my code to read and write image while uploading.  
> could anyone suggest me to solve this issue
> 
> Thanks in advance,
> 
> Regards,  
> Jose Martin

imgs is an array of your animation frames. When you take imgs.first,  
you get only the initial frame.

Try something like this (NOTE: Only run inside my head which tends to  
leak and has no garbage collector. 😉

imgs = Magick::ImageList.from\_blob(image.read)  
imgs.write(RAILS\_ROOT + “/public/images/banner/” + image1)

Or, if you don’t actually do anything with the image:

File.open(RAILS\_ROOT + “/public/images/banner/” + image1 , “wb”) do |f|  
f.write image.read  
end

…and avoid all the ImageMagick overhead.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![martin\_mercy2001](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d2c977/32.png) [@martin\_mercy2001](https://www.ruby-forum.com/u/martin_mercy2001)\
**Post date:** [December 12, 2008, 5:29am UTC](https://www.ruby-forum.com/t/does-animated-gif-will-work-properly-using-rmagick/154833/3 "2008-12-12T05:29:10Z")

</div>

Dear Rob,

Thanks a lot, it works fine now with your below code

> File.open(RAILS\_ROOT + “/public/images/banner/” + image1 , “wb”) do |f|  
> f.write image.read  
> end
> 
> …and avoid all the ImageMagick overhead.
> 
> -Rob

Regards,  
jose Martin
