如果给定的.gif图像不是动画gif,我怎样才能将.gif图像转换为.jpeg?

时间:2016-06-20 03:08:29

标签: ruby-on-rails ruby paperclip

我正在使用Ruby on Rails和RewriteCond %{REQUEST_URI} /(hey|hello|hi)$ RewriteRule ^test/([^/.]+)/(.+)$ /test/$1.php/$2 [NC,L] Gem,如果paper-clip图片不是动画,我想将.gif图片转换为.jpeg .gif

这是我的代码:

gif

1 个答案:

答案 0 :(得分: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宝石。

相关问题