Class: ImageProcessors::KskCrop

Inherits:
Processor
  • Object
show all
Defined in:
lib/image_processors/ksk_crop.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of KskCrop.



5
6
7
8
9
10
# File 'lib/image_processors/ksk_crop.rb', line 5

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

Instance Method Details

#makeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/image_processors/ksk_crop.rb', line 12

def make
  src = @file
  dst = Tempfile.new([@basename, @format])
  dst.binmode
  
  parameters = []
  parameters << ":source"
  parameters << "-crop '#{@crop[2]}x#{@crop[3]}+#{@crop[0]}+#{@crop[1]}'"
  parameters << ":dest"

  parameters = parameters.flatten.compact.join(' ').strip.squeeze(' ')
  
  path = if @file.options && @file.options[:storage] == :s3
    src.url
  else
    File.expand_path(src.path)
  end
  # success = Paperclip.run('convert', parameters, source: path, dest: File.expand_path(dst.path))

  dst
end