Class: Griddle::Processor::ImageMagick

Inherits:
Object
  • Object
show all
Defined in:
lib/griddle/processor/image_magick.rb

Instance Method Summary collapse

Instance Method Details

#cropObject



5
6
7
# File 'lib/griddle/processor/image_magick.rb', line 5

def crop
  `convert #{File.expand_path(@destination_file.path)} -crop #{geometry} -gravity Center #{@destination_file.path}`
end

#crop?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/griddle/processor/image_magick.rb', line 9

def crop?
  @style.geometry =~ /#/
end

#file_heightObject



25
26
27
# File 'lib/griddle/processor/image_magick.rb', line 25

def file_height
  file_dimensions.last
end

#file_widthObject



13
14
15
# File 'lib/griddle/processor/image_magick.rb', line 13

def file_width
  file_dimensions.first
end

#fit(geo = geometry) ⇒ Object



17
18
19
# File 'lib/griddle/processor/image_magick.rb', line 17

def fit(geo = geometry)
  `convert #{File.expand_path(@file.path)} -resize #{geo} #{@destination_file.path}`
end

#geometryObject



21
22
23
# File 'lib/griddle/processor/image_magick.rb', line 21

def geometry
  @geometry ||= @style.geometry.gsub(/#/,'')
end

#heightObject



29
30
31
# File 'lib/griddle/processor/image_magick.rb', line 29

def height
  dimensions.last
end

#process_image(file, style) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/griddle/processor/image_magick.rb', line 33

def process_image file, style
  @style = style
  @file = file
  @destination_file = Tempfile.new @file.original_filename
  if crop?
    fit(resize_geometry_for_crop)
    crop
  else
    fit
  end
  @destination_file
end

#widthObject



46
47
48
# File 'lib/griddle/processor/image_magick.rb', line 46

def width
  dimensions.first
end