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}"
|
|
|
|
|
2023-12-17 14:09:35 -08:00
|
|
|
def size_range = (1.byte)..(5.megabytes)
|
2020-05-02 09:45:11 -07:00
|
|
|
|
|
|
|
def paperclip_path
|
2022-12-21 02:43:32 -08:00
|
|
|
return "/users/:attachment/:id_partition/:style/:basename.:extension" if APP_CONFIG["fog"].blank?
|
2022-07-02 01:19:32 -07:00
|
|
|
|
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
|