Class: Coalla::ImageUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- Coalla::ImageUploader
- Includes:
- CarrierWave::RMagick
- Defined in:
- lib/coalla/uploaders/image_uploader.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#set_image_properties ⇒ Object
You can call this method in your model For example before_save if: :image_changed? do image.set_image_properties end.
- #store_dir ⇒ Object
-
#watermark ⇒ Object
You can call this method with process in your uploader.
Instance Method Details
#set_image_properties ⇒ Object
You can call this method in your model For example before_save if: :image_changed? do
image.set_image_properties
end
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/coalla/uploaders/image_uploader.rb', line 19 def set_image_properties return if !model || !file model.send(setter(:file_name), file.filename) if model.respond_to?(setter(:file_name)) model.send(setter(:size), file.size) if model.respond_to?(setter(:size)) model.send(setter(:content_type), file.content_type) if model.respond_to?(setter(:content_type)) if model.respond_to?(setter(:width)) && model.respond_to?(setter(:height)) w, h = `identify -format "%wx %h" #{file.path.shellescape}`.split(/x/).map { |dim| dim.to_i } model.send(setter(:width), w) model.send(setter(:height), h) end end |
#store_dir ⇒ Object
10 11 12 |
# File 'lib/coalla/uploaders/image_uploader.rb', line 10 def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end |
#watermark ⇒ Object
You can call this method with process in your uploader
33 34 35 36 37 38 39 40 |
# File 'lib/coalla/uploaders/image_uploader.rb', line 33 def watermark return if !model || !model.respond_to?(getter(:watermarked?)) || !model.send(getter(:watermarked?)) manipulate! do |img| logo = Magick::Image.read(Rails.root.join('app/assets/images/watermark.png')).first img.composite(logo, Magick::SouthEastGravity, 0, 0, Magick::OverCompositeOp) end end |