2016-06-20 2 views
0

Ruby on Rails와 paper-clip 보석을 사용 중입니다. .gif 이미지가 애니메이션 인 gif이 아닌 경우 .gif 이미지를 .jpeg으로 변환하고 싶습니다. 나 자신에 의해 해결주어진 .gif 이미지가 애니메이션 gif가 아닌 경우 어떻게 .gif 이미지를 .jpeg로 변환 할 수 있습니까?

has_attached_file :image, styles: Proc.new { |file| file.instance.check_image_gif? ? { 
     :'960' => ["960>x960", :gif], 
     :'640' => ["640>x640", :gif], 
     :'320' => ["320>x320", :gif] 
     }:{ 
     :'960' => ["960>x960", :jpg], 
     :'640' => ["640>x640", :jpg], 
     :'320' => ["320>x320", :jpg] 
     } 
    } 
    def check_image_gif? 
     # I want to check animation gif here. 
     image.instance.image_content_type =~ %r(gif) ? true : false 
    end 
+0

아마도 도움이 될 수 있습니다. http://stackoverflow.com/questions/27238816/how-to-tell-if-gif-is-animated – IngoAlbers

+0

감사합니다.하지만 클립 클립에서 rmagick으로 데이터를 보내는 것을 이해할 수 없습니다. .. –

+0

Paperclip은 이미 ImageMagick을 사용하고 있습니다. 아마도'check_image_gif? '에서'Magick :: ImageList.new (image.url) .scenes> 0'을 시도해 볼 수도 있습니다. – IngoAlbers

답변

0

:

내 코드입니다.

def check_image_gif? 
    begin 
    file = image.instance.image.queued_for_write[:original] 
    img = Magick::Image.read(file.path) 
    animation = (img.size>1) 
    unless animation 
     image.instance.image_content_type = "image/jpeg" 
    end 
    rescue => e 
    end 
    image.instance.image_content_type =~ %r(gif) ? true : false 
end 

나는 rmagick을 추가했습니다.