首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以将jpg/png图像转换为webp格式?如果是,如何在定义回形针的样式散列时使用它?

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

Stack Overflow用户
提问于 2015-05-08 21:45:18
回答 1查看 1.8K关注 0票数 1

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

代码语言:javascript
复制
  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
EN

回答 1

Stack Overflow用户

发布于 2015-05-08 22:09:44

尝试在散列中使用format: :webp

代码语言:javascript
复制
 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 }]
               },     
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30125425

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档