Retrospring/app/uploaders/base_uploader.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.0 KiB
Ruby
Raw Normal View History

2020-05-02 09:45:11 -07:00
class BaseUploader < CarrierWave::Uploader::Base
include CarrierWave::Compatibility::Paperclip
include CarrierWave::MiniMagick
2020-05-17 11:58:27 -07:00
include CarrierWave::Backgrounder::Delay
2020-05-02 09:45:11 -07:00
storage :fog
# Store original size
version :original
2023-12-11 15:20:40 -08:00
process :remove_animation
2020-05-02 09:45:11 -07:00
process :cropping
2023-12-11 15:20:27 -08:00
def content_type_whitelist = %w[image/jpeg image/gif image/png]
def store_dir = "/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
def size_range = (1.byte)..(2.megabytes)
2020-05-02 09:45:11 -07:00
def paperclip_path
return "/users/:attachment/:id_partition/:style/:basename.:extension" if APP_CONFIG["fog"].blank?
2020-05-02 09:45:11 -07:00
"users/:attachment/:id_partition/:style/:basename.:extension"
end
def cropping
x = model.public_send("#{mounted_as}_x")
y = model.public_send("#{mounted_as}_y")
w = model.public_send("#{mounted_as}_w")
h = model.public_send("#{mounted_as}_h")
manipulate! do |image|
image.crop "#{w}x#{h}+#{x}+#{y}"
end
end
2023-12-11 15:20:40 -08:00
def remove_animation
return unless content_type == "image/gif"
manipulate!(&:collapse!)
end
2020-05-02 09:45:11 -07:00
end