Class: Paperclip::Grayscale

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Grayscale.



4
5
6
7
8
9
10
# File 'lib/grayscale_paperclip_processor/grayscale.rb', line 4

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

Instance Method Details

#makeObject



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

def make
  dst = Tempfile.new(@basename)
  dst.binmode
  command = "#{File.expand_path(@file.path)} -resize #{@geometry} -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