Module: Jitimage

Defined in:
lib/jitimage.rb,
lib/jitimage/config.rb

Defined Under Namespace

Modules: Config

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/jitimage.rb', line 7

def self.included(base)
  Jitimage::Config.read
end

Instance Method Details

#jitimage(label = '<no label provided>', options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jitimage.rb', line 11

def jitimage(label = '<no label provided>', options = {})
  options = Jitimage::Config.settings.merge(options)
  hash = MD5.new("#{label}#{options.sort {|a, b| a[0].to_s <=> b[0].to_s}.to_s}")
  path = "#{RAILS_ROOT}/public/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/')
  unless File.exist?(path)
    caption = options[:width] ? "-size #{options[:width]}x caption:'#{label}'" : "label:'#{label}'"
    `mkdir -p #{"#{RAILS_ROOT}/public/#{options[:img_path]}".gsub('//', '/')}`
    `convert -background #{options[:background]} -fill "#{options[:color]}" \
      -font #{Jitimage::Fonts.find(options[:font_dir], options[:font])} \
      -pointsize #{options[:size]} -blur 0x.3 #{caption} #{path}`
  end
  image_tag "/#{options[:img_path]}/#{hash}.#{options[:format]}".gsub('//', '/'),
            :class => (['jitimage'] << options[:class]).compact.join(' '),
            :alt => label
end