ask/app/uploaders/ask_image_uploader.rb

72 lines
1.5 KiB
Ruby

# encoding: utf-8
module CarrierWave
module Uploader
module Versions
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
end
end
class AskImageUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::ImageScience
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
# storage :file
# storage :s3
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def get_org_url
if have_crop?
model.file.resized.url
else
model.file.url
end
end
def fix_exif_rotation
manipulate! do |img|
img.tap(&:auto_orient)
end
end
process :optimize
version :thumb do
process :pad_process => [200,200]
end
version :theater do
process :limit_process => [1920, 1080]
end
version :mobile do
process :limit_process => [1152, 768]
end
def optimize (*arg)
manipulate! do |img|
return img unless img.mime_type.match /image\/jpeg/
img.strip
img.combine_options do |c|
c.quality "90"
c.depth "24"
c.interlace "plane"
end
img
end
end
def limit_process(w,h)
resize_to_limit(w,h)
end
def pad_process (w,h)
resize_and_pad(w, h, :transparent, 'Center')
end
end