Module: CarrierWave::Daltonize

Defined in:
lib/carrierwave-daltonize.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
# File 'lib/carrierwave-daltonize.rb', line 7

def self.included(base)
  base.send(:extend, ClassMethods)
end

Instance Method Details

#daltonize(proc_type) ⇒ Object

daltonize an image file for carrierwave proc_type - the processing type (deuteranope, protanope or tritanope)



21
22
23
24
25
26
27
28
29
30
# File 'lib/carrierwave-daltonize.rb', line 21

def daltonize(proc_type)
  cache_stored_file! unless cached?
  tmp_name = current_path.sub(/(\.[a-z]+)$/i, '_tmp\1')

  ::Daltonize.daltonize_file(current_path, tmp_name, proc_type)

  FileUtils.mv(tmp_name, current_path)
rescue => e
  raise CarrierWave::ProcessingError.new("Failed to manipulate file. Original Error: #{e}")
end