Paperclip可以将jpg / png图像转换为webp格式吗?如果是,在定义回形针的样式哈希时如何使用它?

时间:2015-05-08 13:45:18

标签: ruby-on-rails ruby paperclip webp

我在我的模型中使用回形针压缩,我想在将图像上传到s3之前将图像转换为webp。但转换没有发生,当我访问图像的网址时,我仍然得到了png图像。

  class ImageTesting
  include Mongoid::Document
  include Mongoid::Timestamps
  include Paperclip::Glue

   has_attached_file :image, :processors => [:thumbnail, :compression],
  :styles => {
                :xxlarge_square => ["640x640>",  { lossless: true } , :webp],
                :xlarge_square => ["480x480>",  { lossless: true } , :webp],
                :large_square => ["240x240>",  { lossless: true } ,:webp]
              },
   :convert_options => {
      :all => '-quality 80'
    },

   :storage => :s3,
   :s3_credentials => 'xxx',
   :s3_host_name => 'xxx',
   :s3_host_alias => 'xxx',
   :url => ':s3_alias_url',
   :path => ":class/:attachment/:id/:style"

  field :image_file_name, type: String
  field :image_updated_at, type: DateTime
  field :image_content_type, type: String
  field :image_file_size, type: Integer
end

1 个答案:

答案 0 :(得分:0)

尝试在哈希中使用format: :webp

 has_attached_file :image, :processors => [:thumbnail, :compression],
   :styles => {
                 :xxlarge_square => ["640x640>",  { lossless: true, format: :webp }],
                 :xlarge_square => ["480x480>",  { lossless: true, format: :webp }],
                 :large_square => ["240x240>",  { lossless: true, format: :webp }]
               },