Class: Paperclip::Grayscale

Inherits:
Processor
  • Object
show all
Defined in:
lib/paperclip_processors/grayscale.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ Grayscale

Returns a new instance of Grayscale.



3
4
5
6
7
8
# File 'lib/paperclip_processors/grayscale.rb', line 3

def initialize file, options = {}, attachment = nil
  super
  @file = file
  @current_format = File.extname(@file.path)
  @basename = File.basename(@file.path, @current_format)
end

Instance Method Details

#makeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/paperclip_processors/grayscale.rb', line 10

def make
  dst = Tempfile.new(@basename)
  dst.binmode
  
  command = "#{File.expand_path(@file.path)} -colorspace Gray #{File.expand_path(dst.path)}"
  
  begin
    success = Paperclip.run("convert", command)
  rescue PaperclipCommandLineError
    raise PaperclipError, "There was an error converting the image to grayscale for #{@basename}"
  end
  
  dst
end