2012-03-15 15:00:29 -07:00
|
|
|
require 'carrierwave/processing/mime_types'
|
|
|
|
|
|
|
|
class OutfitImageUploader < CarrierWave::Uploader::Base
|
|
|
|
include CarrierWave::MimeTypes
|
|
|
|
include CarrierWave::MiniMagick
|
|
|
|
|
|
|
|
# Settings for S3 storage. Will only be used on production.
|
2012-07-31 08:42:27 -07:00
|
|
|
fog_directory 'openneo-uploads'
|
2012-03-15 15:00:29 -07:00
|
|
|
fog_attributes 'Cache-Control' => "max-age=#{15.minutes}",
|
|
|
|
'Content-Type' => 'image/png'
|
|
|
|
|
|
|
|
process :set_content_type
|
|
|
|
|
|
|
|
version :medium do
|
|
|
|
process :resize_to_fill => [300, 300]
|
|
|
|
end
|
|
|
|
|
2012-07-17 09:15:04 -07:00
|
|
|
version :small, :from_version => :medium do
|
2012-03-15 15:00:29 -07:00
|
|
|
process :resize_to_fill => [150, 150]
|
|
|
|
end
|
|
|
|
|
|
|
|
def filename
|
2012-07-31 07:39:59 -07:00
|
|
|
"preview.png"
|
2012-03-15 15:00:29 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def store_dir
|
2012-07-31 07:39:59 -07:00
|
|
|
"outfits/#{partition_dir}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# 123006789 => "123/006/789"
|
|
|
|
def partition_dir
|
|
|
|
partitions.map { |partition| "%03d" % partition }.join('/')
|
|
|
|
end
|
|
|
|
|
|
|
|
# 123006789 => [123, 6, 789]
|
|
|
|
def partitions
|
|
|
|
[6, 3, 0].map { |n| model.id / 10**n % 1000 }
|
2012-03-15 15:00:29 -07:00
|
|
|
end
|
|
|
|
end
|