-
Notifications
You must be signed in to change notification settings - Fork 13
/
event_image_uploader.rb
43 lines (33 loc) · 1.1 KB
/
event_image_uploader.rb
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
class EventImageUploader < CarrierWave::Uploader::Base
attr_reader :upload_width, :upload_height
# image processing
include CarrierWave::MiniMagick
storage :file
# Return the directory that images will be uploaded to
# @return [String] the path relative to the `public` folder
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
before :cache, :capture_size_before_cache
# Fill in the upload sizes once the image has been uploaded, so that
# our model can use them for validation
def capture_size_before_cache(new_file)
# Only do this once, to the original version
if version_name.blank?
@upload_width, @upload_height = `identify -format "%wx %h" #{new_file.path}`.split(/x/).map { |dim| dim.to_i }
end
end
version :list_view do
process resize_to_fill: [200, 155]
end
version :detail_view do
process resize_to_fill: [1140, 200]
end
version :thumb do
process resize_to_fill: [50, 50]
end
# white list of extensions which are allowed to be uploaded
def extension_whitelist
%w(jpg jpeg gif png)
end
end