Module: DotDiff::Image::Cropper
- Included in:
- Snapshot
- Defined in:
- lib/dotdiff/image/cropper.rb
Instance Method Summary collapse
- #crop_and_resave(element) ⇒ Object
- #height(element, image) ⇒ Object
- #load_image(file) ⇒ Object
- #width(element, image) ⇒ Object
Instance Method Details
#crop_and_resave(element) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dotdiff/image/cropper.rb', line 8 def crop_and_resave(element) image = load_image(fullscreen_file) # @see http://www.imagemagick.org/script/command-line-options.php?#crop crop_area = '' + width(element, image).to_s + 'x' + height(element, image).to_s + '+' + element.rectangle.x.floor.to_s + '+' + element.rectangle.y.floor.to_s image.crop crop_area image.write(cropped_file) end |
#height(element, image) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/dotdiff/image/cropper.rb', line 26 def height(element, image) element_height = element.rectangle.height + element.rectangle.y image_height = image.height if element_height > image_height image_height - element.rectangle.y else element.rectangle.height end end |
#load_image(file) ⇒ Object
22 23 24 |
# File 'lib/dotdiff/image/cropper.rb', line 22 def load_image(file) MiniMagick::Image.open(file) end |
#width(element, image) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dotdiff/image/cropper.rb', line 37 def width(element, image) element_width = element.rectangle.width + element.rectangle.x image_width = image.width if element_width > image_width image_width - element.rectangle.x else element.rectangle.width end end |