Class: Albums::ImageUploader

Inherits:
CarrierWave::Uploader::Base
  • Object
show all
Includes:
CarrierWave::MiniMagick, Sprockets::Helpers::IsolatedHelper, Sprockets::Helpers::RailsHelper
Defined in:
app/uploaders/albums/image_uploader.rb

Instance Method Summary collapse

Instance Method Details

#cache_dirObject



24
25
26
# File 'app/uploaders/albums/image_uploader.rb', line 24

def cache_dir
  "system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

#store_dirObject

Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:



20
21
22
# File 'app/uploaders/albums/image_uploader.rb', line 20

def store_dir
  "system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

#watermarkObject

Create different versions of your uploaded files: version :thumb do

process :resize_to_fit => [80, 80]

end



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/uploaders/albums/image_uploader.rb', line 48

def watermark
  manipulate! do |img|
    
    albums_watermark = Setting.albums_watermark
    
    watermark_image = if albums_watermark
      MiniMagick::Image.open("#{Rails.root}/public#{albums_watermark.image.url}", "png")
    else
      # We can read a file from system too.
      #MiniMagick::Image.open("#{Rails.root}/app/assets/images/watermarks/watermark.png", "png")
      false
    end

    if watermark_image
      result = img.composite(watermark_image) do |c|
        c.gravity "SouthEast"
      end
      result
    else
      img
    end

  end
end