Optimise/compress 已使用 refile 上传的图片

Optimise/compress images uploaded with refile

有没有办法优化用refile上传的图片?我使用 CDN,所以文件大多只创建一次,但我希望对它们进行优化以节省带宽。

我使用 Mini Magick 进行图像处理,但这也可以用于减小文件大小/优化吗?

处理图像处理的底层工具来自MiniMagick. Image manipulation functionality has been extracted out of Refile into a separate gem, refile-mini_magick. You should be able to write your own processor as described in the readme

也许是这样的:

def quality(percentage)
  manipulate! do |img|
    unless img.quality == percentage
      img.write(current_path) do
        self.quality = percentage
      end
    end

    img = yield(img) if block_given?
    img
  end
end