【问题标题】:convert active storage images to a different format, png to jpg for instance将活动存储图像转换为不同的格式,例如将 png 转换为 jpg
【发布时间】:2021-11-24 16:35:52
【问题描述】:

我想将图像转换为 jpeg/jpg,基本上是这样做的:

  def show
    respond_to do |format|
      format.jpg do
        send_data(
          @event.image.variant(???).download,
          disposition: :inline,
          type: "image/jpeg"
        )
      end
    end
  end

【问题讨论】:

    标签: ruby-on-rails ruby rails-activestorage


    【解决方案1】:

    我需要将gem "vips" 添加到我的Gemfile,然后:

     @event.image.variant(format: :jpg).download
    

    查看合并的相关拉取请求:https://github.com/rails/rails/pull/40226/files

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-01
      • 2023-03-05
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多