Class: Vectory::Datauri
Constant Summary
collapse
- REGEX =
%r{^
data:
(?<mimetype>[^;]+);
(?:charset=[^;]+;)?
base64,
(?<data>.+)
$}x.freeze
Instance Attribute Summary
Attributes inherited from Image
#content
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Image
from_content, from_path, #initialize
Constructor Details
This class inherits a constructor from Vectory::Image
Class Method Details
.from_vector(vector) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/vectory/datauri.rb', line 13
def self.from_vector(vector)
mimetype = vector.class.mimetype
content = vector.content.gsub("\r\n", "\n")
data = Base64.strict_encode64(content)
new("data:#{mimetype};base64,#{data}")
end
|
Instance Method Details
#height ⇒ Object
26
27
28
|
# File 'lib/vectory/datauri.rb', line 26
def height
to_vector.height
end
|
#mime ⇒ Object
21
22
23
24
|
# File 'lib/vectory/datauri.rb', line 21
def mime
match = parse_datauri(@content)
match[:mimetype]
end
|
#to_vector ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/vectory/datauri.rb', line 34
def to_vector
match = parse_datauri(@content)
content = Base64.strict_decode64(match[:data])
image_class = detect_image_class(match[:mimetype])
image_class.from_content(content)
end
|
#width ⇒ Object
30
31
32
|
# File 'lib/vectory/datauri.rb', line 30
def width
to_vector.width
end
|