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
20
21
22
23
24
25
26
|
# File 'lib/vectory/datauri.rb', line 13
def self.from_vector(vector)
mimetype = vector.class.mimetype
content = vector.content
if ["application/postscript", "image/svg+xml"].include?(vector.mime)
content = content.gsub("\r\n", "\n")
end
data = Base64.strict_encode64(content)
new("data:#{mimetype};base64,#{data}")
end
|
Instance Method Details
#height ⇒ Object
33
34
35
|
# File 'lib/vectory/datauri.rb', line 33
def height
to_vector.height
end
|
#mime ⇒ Object
28
29
30
31
|
# File 'lib/vectory/datauri.rb', line 28
def mime
match = parse_datauri(@content)
match[:mimetype]
end
|
#to_vector ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/vectory/datauri.rb', line 41
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
37
38
39
|
# File 'lib/vectory/datauri.rb', line 37
def width
to_vector.width
end
|