2020-05-02 18:45:11 +02:00
|
|
|
class BaseUploader < CarrierWave::Uploader::Base
|
|
|
|
include CarrierWave::Compatibility::Paperclip
|
|
|
|
include CarrierWave::MiniMagick
|
2020-05-17 20:58:27 +02:00
|
|
|
include CarrierWave::Backgrounder::Delay
|
2020-05-02 18:45:11 +02:00
|
|
|
|
|
|
|
storage :fog
|
|
|
|
|
|
|
|
# Store original size
|
|
|
|
version :original
|
|
|
|
|
2023-12-12 00:20:40 +01:00
|
|
|
process :remove_animation
|
2020-05-02 18:45:11 +02:00
|
|
|
process :cropping
|
|
|
|
|
2023-12-12 00:20:27 +01: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 23:09:35 +01:00
|
|
|
def size_range = (1.byte)..(5.megabytes)
|
2020-05-02 18:45:11 +02:00
|
|
|
|
|
|
|
def paperclip_path
|
2022-12-21 11:43:32 +01:00
|
|
|
return "/users/:attachment/:id_partition/:style/:basename.:extension" if APP_CONFIG["fog"].blank?
|
2022-07-02 10:19:32 +02:00
|
|
|
|
2020-05-02 18:45:11 +02: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-12 00:20:40 +01:00
|
|
|
|
|
|
|
def remove_animation
|
|
|
|
return unless content_type == "image/gif"
|
|
|
|
|
|
|
|
manipulate!(&:collapse!)
|
|
|
|
end
|
2020-05-02 18:45:11 +02:00
|
|
|
end
|