Using shrine how can I convert all image uploads to jpegs?

33 Views Asked by At

Using the gem shrine (3.4.0) in RoR I have a hack to convert all image uploads to jpegs, but it uses a deprecated plugin that will be remove in Shrine 4.

class ImageUploader < Shrine
  # Converts all images to jpegs
  process(:store) do |io, context|
    original = io.download
    mime_type = context.try(:[], :record)&.file_data.try(:[], "metadata").try(:[], "mime_type")

    if mime_type != "image/jpeg" || mime_type != "image/jpg"
      # How can we force transparent backgrounds to save as white and not black?
      jpeg = ImageProcessing::Vips
               .source(original)
               .convert("jpeg")
               .saver(quality: 85)
               .call

      original.close

      jpeg
    else
      original.close

      io
    end
  end
end

Works but gives me:

SHRINE DEPRECATION WARNING: The processing plugin is deprecated and will be removed in Shrine 4. If you were using it with versions plugin, use the new derivatives plugin instead.

Any other way to accomplish the same thing? or another plugin I could use?

0

There are 0 best solutions below