Module: Imogen::AutoCrop

Defined in:
lib/imogen/auto_crop.rb,
lib/imogen/auto_crop/edges.rb

Defined Under Namespace

Modules: Box Classes: Edges

Class Method Summary collapse

Class Method Details

.convert(img, dest_path, scale = 768, format = :jpeg) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/imogen/auto_crop.rb', line 5

def self.convert(img, dest_path, scale=768, format=:jpeg)
  frame = Edges.new(img)
  edges = frame.get(scale)
  img.copy(*edges) do |crop|
    crop.rescale(scale, scale) do |thumb|
      dst = FreeImage::File.new(dest_path)
      t24 = (crop.color_type == :rgb) ?  thumb.convert_to_24bits : thumb.convert_to_8bits
      dst.save(t24, format)
      t24.free
      thumb.free
    end
  end
  frame.unlink
end