Module: Applitools::Utils::ImageUtils
- Defined in:
- lib/eyes_selenium/utils/image_utils.rb
Class Method Summary collapse
-
.base64_from_png_image(image) ⇒ Object
Get the Base64 representation of the raw PNG bytes of an image.
-
.bytes_from_png_image(image) ⇒ Object
Get the raw PNG bytes of an image.
-
.png_image_from_base64(png_bytes64) ⇒ Object
Creates an image instance from a base64 representation of its PNG encoding.
-
.png_image_from_bytes(png_bytes) ⇒ Object
Creates an image object from the PNG bytes.
-
.quadrant_rotate!(image, num_quadrants) ⇒ Object
Rotates a matrix 90 deg clockwise or counter clockwise (depending whether num_quadrants is positive or negative, respectively).
Class Method Details
.base64_from_png_image(image) ⇒ Object
Get the Base64 representation of the raw PNG bytes of an image.
ChunkyPNG::Canvas
The image object for which to get the PNG bytes.
Returns: String
the Base64 representation of the raw PNG bytes of an image.
55 56 57 58 59 60 61 62 |
# File 'lib/eyes_selenium/utils/image_utils.rb', line 55 def self.base64_from_png_image(image) EyesLogger.debug "#{__method__}()" png_bytes = bytes_from_png_image(image) EyesLogger.debug 'Encoding as base64...' image64 = Base64.encode64(png_bytes) EyesLogger.debug 'Done!' return image64 end |
.bytes_from_png_image(image) ⇒ Object
Get the raw PNG bytes of an image.
ChunkyPNG::Canvas
The image object for which to get the PNG bytes.
Returns: String
The PNG bytes of the image.
42 43 44 45 46 47 |
# File 'lib/eyes_selenium/utils/image_utils.rb', line 42 def self.bytes_from_png_image(image) EyesLogger.debug "#{__method__}()" png_bytes = image.to_blob EyesLogger.debug 'Done!' return png_bytes end |
.png_image_from_base64(png_bytes64) ⇒ Object
Creates an image instance from a base64 representation of its PNG encoding.
png_bytes64
-
String
The Base64 representation of a PNG image.
Returns: ChunkyPNG::Canvas
An image object.
29 30 31 32 33 34 |
# File 'lib/eyes_selenium/utils/image_utils.rb', line 29 def self.png_image_from_base64(png_bytes64) EyesLogger.debug "#{__method__}()" png_bytes = Base64.decode64(png_bytes64) EyesLogger.debug 'Done!' return png_image_from_bytes(png_bytes) end |
.png_image_from_bytes(png_bytes) ⇒ Object
Creates an image object from the PNG bytes.
png_bytes
-
String
A binary string of the PNG bytes of the image.
Returns: ChunkyPNG::Canvas
An image object.
16 17 18 19 20 21 |
# File 'lib/eyes_selenium/utils/image_utils.rb', line 16 def self.png_image_from_bytes(png_bytes) EyesLogger.debug "#{__method__}()" image = ChunkyPNG::Image.from_blob(png_bytes) EyesLogger.debug 'Done!' return image end |
.quadrant_rotate!(image, num_quadrants) ⇒ Object
Rotates a matrix 90 deg clockwise or counter clockwise (depending whether num_quadrants is positive or negative, respectively).
image
-
ChunkyPNG::Canvas
The image to rotate. num_quadrants
-
Integer
The number of rotations to perform. Positive values are used for clockwise rotation and negative values are used for counter-clockwise rotation.
71 72 73 74 75 |
# File 'lib/eyes_selenium/utils/image_utils.rb', line 71 def self.quadrant_rotate!(image, num_quadrants) rotate_method = num_quadrants > 0 ? image.method('rotate_right!'.to_sym) : image.method('rotate_left!'.to_sym) (0..(num_quadrants.abs-1)).each { rotate_method.call } return image end |