Search code examples
rubycarrierwavermagick

Convert animated gif to one image with Rmagic (image magic)


I know there is a way to convert several images to gif animation with Rmagic, however I want to do the opposite. When uploading an animated gif, I want it to be non-animated, how can I do that ? (single/any image from image stream is good enough)

I'll use this as a part of carrierwave with Rmagic reprocessoring on thumbnails


Solution

  • from https://stackoverflow.com/a/13441569/473040

    class DocumentUploader < CarrierWave::Uploader::Base
    include CarrierWave::RMagick
    #...
    
        version :thumb do
          process :remove_animation
          process :resize_to_fill => [300,200]
    
          #....
        end    
    
        def remove_animation
          # this will keep only first image of animated gif
          manipulate! do |img, index|
          index == 0 ? img : nil
        end
    
    end
    

    thx Padde and Tiago Franco