Class: PhotoUploader
- Inherits:
-
ApplicationUploader
- Object
- CarrierWave::Uploader::Base
- ApplicationUploader
- PhotoUploader
- Includes:
- ImageDefaults
- Defined in:
- app/uploaders/photo_uploader.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
Methods included from ImageDefaults
Methods inherited from ApplicationUploader
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
46 47 48 |
# File 'app/uploaders/photo_uploader.rb', line 46 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
46 47 48 |
# File 'app/uploaders/photo_uploader.rb', line 46 def width @width end |
Instance Method Details
#capture_size(file) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/uploaders/photo_uploader.rb', line 50 def capture_size(file) return unless version_name.blank? if file.path.nil? img = ::MiniMagick::Image.read(file.file) @width = img[:width] @height = img[:height] else @width, @height = `identify -format "%wx %h" #{file.path}`.split(/x/).map(&:to_i) end end |
#default_url ⇒ Object
6 7 8 |
# File 'app/uploaders/photo_uploader.rb', line 6 def default_url ActionController::Base.helpers.asset_path('images/default_photo.png') end |
#present? ⇒ Boolean
19 20 21 |
# File 'app/uploaders/photo_uploader.rb', line 19 def present? super && width.present? && height.present? end |
#url ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'app/uploaders/photo_uploader.rb', line 10 def url if file.present? && File.exist?(file.file) file.file.match(%r{/system/uploads/.*}).to_s else default_url = '/assets/tramway/core/mona_lisa_from_prado_square.jpg' File.exist?(default_url) ? default_url : '' end end |