2

我在我的模型中使用回形针压缩,我想在将图像上传到 s3 之前将其转换为 webp。但是转换没有发生,当我访问图像的 url 时,我仍然得到 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
4

1 回答 1

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 }]
               },     
于 2015-05-08T14:09:44.007 回答