Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shrine images #396

Merged
merged 10 commits into from
Apr 8, 2022
18 changes: 18 additions & 0 deletions spec/dummy/app/uploaders/image_uploader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'image_processing/vips'

class ImageUploader < Shrine
DERIVATIVE_SIZES = {
jpg_small: { size: [100, 100], type: 'jpg' }
}

Attacher.derivatives do |original|
vips = ImageProcessing::Vips.source(original)

DERIVATIVE_SIZES.reduce({}) do |derivatives_hash, (name, derivative_info)|
derivatives_hash[name] = vips.convert(derivative_info[:type]).resize_to_limit!(
*derivative_info[:size]
)
derivatives_hash
end
end
end