Skip to content

How to use mime_type in derivatives block? #667

Closed Answered by janko
jeremyhaile asked this question in Q&A
Discussion options

You must be logged in to vote

You can pass download: false to the Attacher.derivatives call, and download the uploaded file yourself:

Attacher.derivatives(download: false) do |source|
  next {} if %w[video/mpeg image/gif ...].include?(source.mime_type)
  shrine_class.with_file(source) do |file|
    magick = ImageProcessing::MiniMagick
      .source(file)
      .saver(quality: 60)

    {
      thumbnail: magick.coalesce.resize_to_limit!(128, 128),
      optimized: magick.coalesce.resize_to_limit!(1024, 1024)
    }
  end
end

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jeremyhaile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants