How to use mime_type in derivatives block? #667
-
I'd like access to the derived mime_type (or all of the metadata) when creating derivatives, but the derivatives block only takes in "original" (a reference to the original file)
Is there any way to access that there? I tried using The specific problems I'm trying to handle are:
My full code right now looks like this:
|
Beta Was this translation helpful? Give feedback.
Answered by
janko
Jan 3, 2024
Replies: 1 comment
-
You can pass 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 |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jeremyhaile
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass
download: false
to theAttacher.derivatives
call, and download the uploaded file yourself: