Module: WallOperations

Included in:
WallMerger, WallScaler
Defined in:
lib/wall_operations.rb

Instance Method Summary collapse

Instance Method Details

#get_scaled_size(image, width_bound, height_bound) ⇒ Object

Returns a scale factor for the image with the given bounds



15
16
17
18
19
20
21
22
23
24
# File 'lib/wall_operations.rb', line 15

def get_scaled_size(image, width_bound, height_bound)
  width_multiplier  = 1.0 * width_bound / image.columns
  height_multiplier = 1.0 * height_bound / image.rows

  if image.rows * width_multiplier <= height_bound
    width_multiplier
  else
    height_multiplier
  end
end

#place_onto(x, y, image, target) ⇒ Object

Places image on target where top left corner of image goes to x and y coordinates



43
44
45
# File 'lib/wall_operations.rb', line 43

def place_onto(x, y, image, target)
  target.import_pixels(x, y, image.columns, image.rows, 'RGB', image.export_pixels)
end

#place_through(x, y, width_bound, height_bound, image, target) ⇒ Object

Places image on target, also applying rightward or downward shift to given coordinates based on bounds



36
37
38
39
40
# File 'lib/wall_operations.rb', line 36

def place_through(x, y, width_bound, height_bound, image, target)
  new_x = (width_bound  - image.columns) / 2 + x
  new_y = (height_bound - image.rows)    / 2 + y
  place_onto(new_x, new_y, image, target)
end

#prepare_backdrop(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/wall_operations.rb', line 26

def prepare_backdrop(options = {})
  color      = options['color']  || 'black'
  width_one  = options['width']  || options['width_one']  || 1920
  height_one = options['height'] || options['height_one'] || 1200
  width_two  = options['width_two']  || 0
  height_two = options['height_two'] || 0
  Image.new(width_one + width_two, [height_one, height_two].max) { self.background_color = color}
end

#prepare_image(image_name, width_bound, height_bound) ⇒ Object

Minimally scales image to fill width_bound and height_bound. Will not overflow bounds



6
7
8
9
10
11
12
# File 'lib/wall_operations.rb', line 6

def prepare_image(image_name, width_bound, height_bound)
  im = ImageList.new(image_name)
  scale_factor = get_scaled_size(im, width_bound, height_bound)
  im.scale!(scale_factor)

  im
end

#save_image(image, title) ⇒ Object



47
48
49
# File 'lib/wall_operations.rb', line 47

def save_image(image, title)
  image.write(title)
end