Class: Watir::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/watir-get-image-content/image.rb

Instance Method Summary collapse

Instance Method Details

#to_jpgObject


31
32
33
# File 'lib/watir-get-image-content/image.rb', line 31

def to_jpg
  Base64.decode64(self.to_jpg_base64)
end

#to_jpg_base64Object


23
24
25
# File 'lib/watir-get-image-content/image.rb', line 23

def to_jpg_base64
  to_x_base64('jpg')
end

#to_pngObject


27
28
29
# File 'lib/watir-get-image-content/image.rb', line 27

def to_png
  Base64.decode64(self.to_png_base64)
end

#to_png_base64Object


19
20
21
# File 'lib/watir-get-image-content/image.rb', line 19

def to_png_base64
  to_x_base64('png')
end

#to_x_base64(target) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/watir-get-image-content/image.rb', line 7

def to_x_base64(target)
  assert_exists
  js = %Q{var canvas = document.createElement("canvas");
          canvas.width = arguments[0].width;
          canvas.height = arguments[0].height;
          var ctx = canvas.getContext("2d");
          ctx.drawImage(arguments[0], 0, 0);
          var dataURL = canvas.toDataURL("image/#{target}");
          return dataURL.replace(/^data:image\\/(png|jpg|gif);base64,/, "");}
  driver.execute_script js, @element
end