Sha256: 900b22a76f00e21ea1237ad97b2e0a7d9cf1c9a45e08b045ba81bd5bed064074
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
module RailsUploads module Types class Image < File def has_presets? presets.any? end def presets Rails.application.config.uploads.default_presets | (@options[:presets] or []) end def store super() do if has_presets? presets.each do |name| generate_preset name end end end end def delete super() do if has_presets? presets.each do |name| ::File.delete realpath(name) if exists? name end end end end protected def generate_preset(name) create_dir(name) image = RailsUploads::Magick::Image.new(realpath, realpath(name)) settings = Rails.application.config.uploads.presets[name] if settings.is_a? Proc thumbnail = settings.call(image) else case settings[:method] when :fit thumbnail = image.resize_to_fit(settings[:width], settings[:height]) else thumbnail = image.resize_to_fill(settings[:width], settings[:height]) end end end def store_path(*args) ::File.join('images', (args[0] ? args[0].to_s.gsub('_', '-') : 'original')) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails_uploads-0.1.5 | lib/rails_uploads/types/image.rb |