Module: DotDiff::Image::Cropper

Included in:
Snapshot
Defined in:
lib/dotdiff/image/cropper.rb

Instance Method Summary collapse

Instance Method Details

#crop_and_resave(element) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/dotdiff/image/cropper.rb', line 6

def crop_and_resave(element)
  image = load_image(fullscreen_file)

  image.crop!(
    element.rectangle.x,
    element.rectangle.y,
    width(element, image),
    height(element, image)
  )

  image.save(cropped_file)
end

#height(element, image) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/dotdiff/image/cropper.rb', line 23

def height(element, image)
  element_height = element.rectangle.height + element.rectangle.y

  if element_height > image.height
    image.height - element.rectangle.y
  else
    element.rectangle.height
  end
end

#load_image(image_file) ⇒ Object



19
20
21
# File 'lib/dotdiff/image/cropper.rb', line 19

def load_image(image_file)
  ::ChunkyPNG::Image.from_file(image_file)
end

#width(element, image) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/dotdiff/image/cropper.rb', line 33

def width(element, image)
  element_width = element.rectangle.width + element.rectangle.x

  if element_width > image.width
    image.width - element.rectangle.x
  else
    element.rectangle.width
  end
end