Retrospring/app/uploaders/base_uploader.rb

33 lines
757 B
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
# Process cropping on upload
process :cropping
def store_dir
"/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def paperclip_path
"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
end