Initial commit
This commit is contained in:
21
spec/support/base64_image.rb
Normal file
21
spec/support/base64_image.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class Base64Image
|
||||
attr_reader :data_uri
|
||||
|
||||
def initialize(data_uri)
|
||||
@data_uri = data_uri
|
||||
end
|
||||
|
||||
# Creates an instance from a given file path which is converted to a base64 data uri
|
||||
def self.from_image(path, mime_type = "image/png")
|
||||
data = Base64.encode64(File.open(path, "rb").read)
|
||||
data_uri = "data:#{mime_type};base64,#{data}"
|
||||
|
||||
new(data_uri)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def encoded_image
|
||||
@data_uri.split(",")[1]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user