Class: NitroIntelligence::Image

Inherits:
Media
  • Object
show all
Defined in:
lib/nitro_intelligence/media/image.rb

Instance Attribute Summary collapse

Attributes inherited from Media

#base64, #byte_string, #direction, #file_extension, #file_type, #mime_type, #reference_id

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Image

Returns a new instance of Image.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/nitro_intelligence/media/image.rb', line 18

def initialize(file)
  super

  image = MiniMagick::Image.read(StringIO.new(file))

  @mime_type = image.mime_type
  @height = image.height
  @width = image.width

  parse_mime_type
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/nitro_intelligence/media/image.rb', line 8

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/nitro_intelligence/media/image.rb', line 8

def width
  @width
end

Class Method Details

.from_base64(base64_string) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/nitro_intelligence/media/image.rb', line 10

def self.from_base64(base64_string)
  # Strip data_uri from string
  base64_string = base64_string.sub(/^data:[^;]*;base64,/, "")
  byte_string = Base64.strict_decode64(base64_string)

  new(byte_string)
end