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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Dec-04 13:46 UTC
Re: Does animated gif will work properly using RMagick?
On Dec 4, 2008, at 3:56 AM, dare ruby wrote:> 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 Martinimgs 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 Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. > > -RobRegards, jose Martin -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---