public
Created

Uploaders Inheritance

  • Download Gist
ambiance_image_uploader.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11
class AmbianceImageUploader < ImageUploader
version :header do
process :resize_to_fill => [get_width(6), 350+10]
process :convert => :jpg
end
 
def filename
"ambiance.jpg" if original_filename
end
 
end
image_uploader.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
# encoding: utf-8
 
class ImageUploader < CarrierWave::Uploader::Base
 
include CarrierWave::MiniMagick
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :file
 
def store_dir
"images/#{model.class.to_s.underscore}/#{model.slug}"
end
 
def default_url
asset_path("fallback/" + [version_name, "image.jpg"].compact.join('_'))
end
 
def self.get_width(span)
grid_column_width = 110
grid_gutter_width = 10
return grid_column_width if span <= 0 or span > 8
(span*grid_column_width) + ((span>1 ? span-1 : 0)*grid_gutter_width)
end
 
def self.get_height(width)
ratio = 180/150
width/ratio
end
 
def self.dims(span)
width = get_width(span)
[width, get_height(width)]
end
 
version :xlarge do
process :resize_to_limit => dims(8)
process :convert => :jpg
end
 
version :large do
process :resize_to_limit => dims(4)
process :convert => :jpg
end
 
version :medium do
process :resize_to_limit => dims(2)
process :convert => :jpg
end
 
version :small do
process :resize_to_limit => dims(1)
process :convert => :jpg
end
 
version :xsmall do
process :resize_to_limit => dims(0.5)
process :convert => :jpg
end
 
def extension_white_list
%w(jpg jpeg gif png tiff tif)
end
 
def filename
"image.jpg" if original_filename
end
 
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.