Class: Suma::Jsdai::FigureImage

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/jsdai/figure_image.rb

Overview

Represents a JSDAI figure image file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_file) ⇒ FigureImage



11
12
13
14
15
16
17
# File 'lib/suma/jsdai/figure_image.rb', line 11

def initialize(image_file)
  @path = image_file
  @base64_data = nil
  @width = nil
  @height = nil
  @image_type = extract_image_type
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/suma/jsdai/figure_image.rb', line 9

def height
  @height
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/suma/jsdai/figure_image.rb', line 9

def path
  @path
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/suma/jsdai/figure_image.rb', line 9

def width
  @width
end

Instance Method Details

#dimensionsObject



26
27
28
29
# File 'lib/suma/jsdai/figure_image.rb', line 26

def dimensions
  extract_dimensions unless @width && @height
  [@width, @height]
end

#to_base64Object



19
20
21
22
23
24
# File 'lib/suma/jsdai/figure_image.rb', line 19

def to_base64
  @to_base64 ||= begin
    image_data = File.binread(@path)
    "data:image/#{@image_type};base64,#{Base64.strict_encode64(image_data)}"
  end
end